简体   繁体   English

在C中返回结构的函数中的编译错误

[英]compilation error in function returning a struct in C

I keep getting this compilation error: 我不断收到此编译错误:

error: expected ';', ',' or ')' before '&' token 错误:“&”标记之前的预期“;”,“,”或“)”

on the marked line below: 在下面的标记行上:

//128 bit vector struct (4 integers)
typedef struct {
  int w, x, y, z;
} iVector4;

iVector4 SSEadd(iVector4 &v1, iVector4 &v2)  // <-- this line
{
  iVector4 vr;
  asm
  {
    MOV EAX v1
    MOV EBX v2
    //
    MOVUPS XMM0, [EAX]
    MOVUPS XMM1, [EBX]
    //
    PADDD XMM0 XMM1
    MOVUPS [rv]
  }
  return rv;
}

I really can't see what's wrong: What seems to be the problem? 我真的看不到出什么问题了:似乎是什么问题?

EDIT: 编辑:

Hi thanks for all the responses. 您好,感谢您的所有回复。

I'm using gcc as a compiler, and I realize that the assembly code that I had provided was also incorrect.I was wondering if its best to use the built_in functions from -msse/-msse2. 我使用gcc作为编译器,但我意识到我提供的汇编代码也不正确,我想知道是否最好使用-msse / -msse2中的内置函数。

Also, what's the most efficient way to load and extract values from a vector such as v4si? 此外,从矢量(例如v4si)中加载和提取值的最有效方法是什么?

I'm finding that loading and extracting from the vector is a costly ooperation. 我发现从向量加载和提取是昂贵的操作。

When you say sse intrinsics, what exactly did you mean? 当您说sse内在函数时,您到底是什么意思?

Thanks for all the help. 感谢您的所有帮助。

C does not have references. C没有参考。 You need to compile as C++ for those. 您需要将其编译为C ++。

C doesn't have references. C没有参考。 You should use a pointer instead, or use C++. 您应该改用指针,或使用C ++。

iVector4 SSEadd(iVector4 *v1, iVector4 *v2)

Now the next question - can you return objects in C? 现在下一个问题-您可以用C返回对象吗? My C is rusty. 我的C生锈了。 If that's the not case, you'd need: 如果不是这种情况,则需要:

void  SSEadd(iVector4 *v1, iVector4 *v2, iVector4 *vOut)

EDIT: As Justin pointed out, it is possible, so you don't need to go that route. 编辑:正如贾斯汀指出的那样,这是有可能的,因此您不需要走那条路线。 You still could though - depending on the circumstances, it could be more performant. 不过,您仍然可以-根据情况而定,它的性能可能更高。

我认为您的函数定义实际上应该是:

iVector4 SSEadd(iVector4 *v1, iVector4 *v2);

您可能还想考虑使用SSE内在函数,而不是看起来像在做什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM