c++ - Where is the best place to put the #ifdef __cplusplus extern "C" { #endif -


i know better put the

#ifdef __cplusplus extern "c" { #endif 

in c header file.

at beginning or after other includes. why ?

there no strict rules on this, note following.

  1. the general principle each header file takes care of (and self sufficient). so, principle, there no need wrap header files in extern "c", because header files have extern "c" in them (if need one). so, in current file, place after other includes.
  2. but if have whole bunch of headers, don't want add extern "c" to, , want make available through single include, means, go ahead , wrap them in file wide extern "c".

just know idea behind extern "c" makes compiler generate c friendly linkage. otherwise, code compiled c++ compiler looks mangled names link against in archives compiled c compiler, , can't find them.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -