错误:从“ int*”转换为“ int” [-fpermissive]
error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
获取错误:
错误:从" int*"转换为" int" [-fpermissive] 在G
上
在以下代码上:
void* func(void *s)
{
int i = 0;
int self = (int *)s;
printf("Thread Entered: %dn", self);
sm.lock(self);
// Critical section (Only one thread
// can enter here at a time)
for (i=0; i<MAX; i++)
ans++;
sm.unlock(self);
}
您需要将int self = (int *)s;
更改为int self = *((int *)s);
或int * self = (int *)s;
。
您需要将这些视为两种不同的东西。一个是通往存储值的内存的指针(int*
),另一个是实际值(int
)。
查看您的函数声明
void* func(void *s)
,您的s
参数是类型void
,如果您想转换它,则需要为int
。
您的数据类型似乎有些混杂,在C/C 中的飞行效果不佳。可以清洁它吗?如果您使用pthread_create()
使用此功能,则根据该功能的示例,请尝试..
// your pthread_create call..
int SOME_INT = 123;
s = pthread_create(&thread_id, &attr, &thread_start, &SOME_INT);
//...and your function
void* func(void *s)
{
int self = (int*) s;
指针可能会令人困惑。查看上面的代码是否看起来相似,特别是将pthread_create
作为指针参考的最后一个参数。然后尝试您的原始代码。可能只是不是作为参考。
看看您的产生的东西,否则尝试将其存储为指针,然后在使用中转换。
void* func(void *s)
{
int *self = s;
sm.lock(*self); // but can give a potential race condition.
相关文章:
- 为什么在全局范围内使用"extern int a"似乎不行?
- int(c) 和 c-'0' 之间的区别。C++
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 是否可以从int转换为enum类类型
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- 'short int'持有的值溢出,但"自动"不会溢出?
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- 调用'begin(int [n])'没有匹配函数
- 没有显式声明的int[]中的foreach
- 错误:从“ int*”转换为“ int” [-fpermissive]
- 将矩阵传递给函数。 "invalid conversion from 'int (*)[columns]' to 'int' [-fpermissive]"
- 枚举上的"no 'operator++(int)' declared for postfix '++' [-fpermissive]"
- 从“char*”到“char”[-fpermissive]的转换无效,数组下标的类型“char[int]”无效
- 错误:在makefile中从' void* '转换为' int '会失去精度[-fpermissive]
- 从' int '到' int* '的转换无效[-fpermissive]
- 错误:从“const char*”到“int”的转换无效[-fpermissive]