Why are aligned arguments compiled correctly, but run-time failures occur?

I have this code in two VS2010 projects:

__declspec(align(16)) struct S { int a; }; void f(S v) {} 

It should not compile, because you cannot pass agreed arguments to functions (unless you pass them by reference); and one project rejects it, as I expected. But another project compiles it OK, and then it crashes at runtime.

My question is: why is it ever allowed to compile?

I looked through all the compiler options, and I cannot find anything relevant.

+4
source share
1 answer

Have you verified that you do not have a macro named align? If not, then put

 #undef align 

directly above the code and recompile. If it fails, you have this macro defined somewhere.

0
source

Source: https://habr.com/ru/post/1447048/


All Articles