+ 1

Extern vs extern "C"

Hi 1. I had thought that extern is used to modify the variable in different translation unit... For example, //this is in main.cpp namespace Abc { extern int x; }; //also in main.cpp int Abc::x = 0; above means x is declared in namespace but main.cpp has also its scope (outside of namespace as well) and initialized to 0 Is above correct ? Next query is as below : 2. What if i have extern "C" int x; in question 1? Is extern "C" not only used for namemangling and tell that this can be accessed in c code as well ? With extern "C" also, do we get same effect of extern alone ?

21st Aug 2022, 9:56 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
1 Answer
22nd Aug 2022, 12:18 AM
Tina
Tina - avatar