Is C code still considered C++?

前端 未结 8 1286
小鲜肉
小鲜肉 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:36

    In general, yes C code is considered C++ code.

    But C is not a proper subset in a strict sense. There are a couple of exceptions.

    Here are some valid things in C that are not valid in C++:

    int *new;//<-- new is not a keyword in C
    char *p = malloc(1024); //void * to char* without cast 
    

    There are more examples too, but you get the idea.

    I previously wrote a more extensive answer in a similar question here.

提交回复
热议问题