Is C code still considered C++?

前端 未结 8 1283
小鲜肉
小鲜肉 2021-01-11 22:52

The comment to this answer got me wondering. I\'ve always thought that C was a proper subset of C++, that is, any valid C code is valid C++ code by extension. Am I wrong a

8条回答
  •  盖世英雄少女心
    2021-01-11 23:25

    typedef struct {
         int a, b, c;
    } st;
    
    st s = {
        .a = 1,
        .b = 2,
    };
    

    This is valid C code which does not compile in most C++ compilers. It is not part of the C++ spec as far as I know. However, some C++ compilers are "liberal" with certain parts of the language and allow things they shouldn't, just as a lot miss out on a few nuances that are in the spec but almost never used.

提交回复
热议问题