我只是在没有完整内存管理的系统上使用此代码:
typedef unsigned short component_t;
typedef struct {
component_t* c; // least-significant word first
unsigned int num_components; // number of unsigned short rows
} integer;
integer result;
result.c=malloc(component_t*)malloc(sizeof(component_t)*128); //this is just an example to tell I'm correctly initializing. There's no malloc nor memset inside OpenCL. currently, I'm trying to speed up the code serially before switching to OpencL. That's also why I don't use GMP.
result.num_components=128
下一行:
for(int i=0;i<result.num_components/4;i++) (unsigned long)result.c[i] = 26; // assign 26 in that part of the memory
触发:
gcc integer.c
integer.c:567:36 error: lvalue required as left operand of assignment
(unsigned long)result.c[5] = 26;
^
我不知道该行的真正问题以及我到底需要写什么来纠正这个问题。
注意:我也见过(即使这没用):
for(int i=0;i<result.num_components/4;i++) (unsigned long)result.c[i]++
编译时
for(int i=0;i<result.num_components/4;i++) (unsigned long)result.c[i]+=1
没有。
最佳答案
integer.c:567:36 error: lvalue required as left operand of assignment (unsigned long)result.c[5] = 26; ^
result.c[5]
的值被检索并转换为unsigned long
,这会给您留下类似于 15 = 26
的分配。您(大概)想要的是转换 result.c
指向 unsigned long
的指针 :
((unsigned long *)result.c)[5] = 26;
关于类型转换 : lvalue required as left operand of assignment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24255019/