How to enforce C89-style variable declarations in gcc?

前端 未结 3 1012
执笔经年
执笔经年 2021-02-07 23:55

I work on a code base which is mostly C with a little C++, and is mostly built with gcc but occasionally it needs to be built with MSVC. Microsoft\'s C compiler is still pretty

3条回答
  •  误落风尘
    2021-02-08 00:33

    I don't believe there is a way to do what you want. The dialect of C supported by MSVC is closer to C89 than C99 (eg. it doesn't support designated initializers either); you really want something more akin to C89-with-C++-comments-and-inline-keyword.

    The problem with that is that C++ comments can affect the correctness of valid C89 code. For example, the meaning of this line changes substantially:

    int a = 10//* foo */2;
    

    I'd say your best bet is to enforce C89 in your C source files, including C89-style comments. inline is probably OK, though: you can define it to __inline on gcc.

提交回复
热议问题