小编elh*_*ɥןǝ的帖子

声明"int t [0];"的目的是什么?服务?

以下声明的目的是什么?

struct test
{
     int field1;
     int field2[0];
};
Run Code Online (Sandbox Code Playgroud)

c c99

4
推荐指数
1
解决办法
263
查看次数

'typeof'之前的预期表达式或'typeof'之前预期的primary-expression

我有一个像这样的宏:

#include <stdio.h>
#include <stddef.h>

#define m_test_type(e)                              \
    do {                                            \
         if (typeof(e) == typeof(char [])) {        \
            printf("type is char []\n");            \
         } else                                     \
         if (typeof(e) == typeof(int)) {            \
            printf("type is int\n");                \
         } else {                                   \
            printf("type is unknown\n");            \
         }                                          \
     } while (0)

int main() {
    char s[] = "hello";

    m_test_type(s);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在使用gcc编译期间,我收到以下错误:

prog.cpp: In function 'int main()':
prog.cpp:6:14: error: expected primary-expression before 'typeof'
          if (typeof(e) == typeof(char *)) {         \
              ^ …
Run Code Online (Sandbox Code Playgroud)

c macros gcc

3
推荐指数
1
解决办法
4171
查看次数

标签 统计

c ×2

c99 ×1

gcc ×1

macros ×1