Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens if I use extern "C++" with a C toolchain?

Tags:

c++

c

extern

My question is mainly about the fact that a C++ toolchain "understands" both C and C++, so if I feed some code with an extern "C" to a c++ toolchain I assume it can understand what to do with that; but what if I feed code with extern "C++" to a C toolchain ?

What is the expected behaviour ?

like image 337
user2485710 Avatar asked Aug 17 '13 12:08

user2485710


1 Answers

If the compiler ALSO understands C++, it may accept it. If it's a pure C compiler it will object (just like it will on extern "C" as that syntax is not valid C - this is why it's typically enclosed with #ifdef __cplusplus or some such)

like image 138
Mats Petersson Avatar answered Oct 05 '22 23:10

Mats Petersson