- 论坛徽章:
- 0
|
#include <stdio.h>
#include <string.h>
#define is_ptr(x) __builtin_types_compatible_p(typeof(x), typeof(&x[0]))
#define get_u16(X,O) (*(unsigned short *)((unsigned long)X + O))
#define test_memeql(b, m) \
(sizeof(char [1 - 2 * is_ptr(m)]) * 0 + !memcmp((b), (m), sizeof(m) - 1))
int main()
{
char *m="abcdxyzuvwefghijklmn";
int ret;
ret = test_memeql(m,"bcd");
printf("%d\n",is_ptr(m));
printf("%d\n",ret);
return 0;
}
这个能正常编译!本人有疑问!
因为is_ptr(m)结果是1, 那么sizeof(char[1-2*is_ptr(m)]) === sizeof(char[1-2*1]) === sizeof(char[-1])
在ubuntu上试验了!sizeof(char【1】)是单独编译不过的。为什么同样在ubuntu上编译 这个就能编译过!奇怪!
求解答 |
|