我读到这个代码是根据c标准未定义但我无法找到原因.它在gcc 8.1.0和clang-6.0中编译没有错误并打印1.
代码如下:
#include <stdio.h>
int main()
{
union {
int i;
short s;
} u;
u.i = 42;
u.s = 1;
printf("%d\n", u.i);
return 0;
}
Run Code Online (Sandbox Code Playgroud) I find no difference between these two macros except the parentheses surrounding the macro in the first one.
Is it a matter of readability or is it a way to deal with the priority of operators?
#define TAM_ARRAY(a) (sizeof(a)/sizeof(*a))
#define TAM_ARRAY2(a) sizeof(a)/sizeof(*a)
Run Code Online (Sandbox Code Playgroud)