一元*的类型冲突error和无效类型参数具有int
Conflicting types error and invalid type argument of unary * have int
我这里有一个非常简单的程序,我会得到错误,比如:
conflicting type of 'f'
previous declaration of 'f' was here
error : initializer element is not computable at load time
in function queue_ready:
invalid type argument of unary '*' (have'int')
in function dequeue_ready :
invalid type argument of unary '*' (have'int')
我的错误在哪里?
#include<stdio.h>
int Queue_ready[1000];
int *r ;
int *f ;
r=&Queue_ready[0];
f=&Queue_ready[0];
void queue_ready (int process)
{
*r=process;
r = r+1;
}
void dequeue_ready (void)
{
*f = 10000;
f=f+1;
}
int main()
{
queue_ready(1);
queue_ready(2);
printf("%d %d" , Queue_ready[0] ,Queue_ready[1]);
dequeue_ready();
dequeue_ready();
return 0;
}
问题就在这里:
int *r;
int *f;
r=&Queue_ready[0];
f=&Queue_ready[0];
这些线位于函数之外。前两个是可以的,因为它们声明变量,但后两个则不然,因为它们是语句,并且不允许在函数之外使用语句。
出现"冲突类型"错误的原因是,语句(编译器不期望)被读取为声明。由于这个"声明"没有指定类型,所以它有一个隐含的类型int
,这与之前类型int *
的定义相冲突。
因为您实际想要做的是初始化这些变量(与赋值相反),所以您在声明它们时这样做:
int *r = &Queue_ready[0];
int *f = &Queue_ready[0];
相关文章:
- 在 c++ 中的模板实例化中使用带有构造函数的类作为类型参数
- 如何解决一元"*"(有"字符")错误的无效类型参数?
- "std::shared_ptr":不是参数"_Ty"的有效模板类型参数
- 具有可变参数非类型参数的模板专用化
- 错误:一元"*"的类型参数无效(具有"int"):使用 mergesort 计算
- 错误 带有模块的一元"*"(具有"int")的类型参数无效
- 一元'*'的类型参数无效(有双精度)
- 即使我传递了无效的类型参数,我为什么还能在没有错误的情况下编译此代码
- C++:无效的类型参数"->"
- 3 错误:错误:未在此范围内声明'Entry'。错误:模板参数 1 无效。错误:令牌之前声明中的类型无效'('
- 一元*的类型冲突error和无效类型参数具有int
- 映射迭代器:一元'*'的无效类型参数(具有"int")
- 一元 '*' 的 #define 和无效类型参数(具有 'double')
- 一元'*'的类型参数无效(有"布尔")
- 数组中一元'*'(具有"int")最低元素的类型参数无效
- 一元“*”的类型参数无效
- 错误:一元“*”(具有“int”)的类型参数无效
- 如何修复"'一元'类型参数无效?
- 如何修复"'一元*'的无效类型参数?
- 错误:一元'*'的类型参数无效