Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The least confusing thing (at least for me) to do is to make the declarations in the header match the function definitions. As other answers have mentioned, it's the declaration/prototype that matters most - the <code>extern "C"</code> linkage specification can be omitted from the function definition as long as the prototype has been 'seen' by the compiler already when it gets to the definition. However, personally I find it preferable and less potentially confusing to have the declarations and the definitions match, but that's a preference that other programmers might not share.</p> <p>Note that you don't have to <code>extern "C"</code> everything in a header or implementation file - the <code>extern "C"</code> can be applied to a single name or to a group of names (by applying it to a block).</p> <p>So, in your header you can have something like:</p> <pre><code>// entrypoints.h #ifdef __cplusplus // this opens an extern "C" block, but only if being included for a C++ compile // if this is being included in a C compile, the extern "C" bits won't be seen extern "C" { #endif int foo(void); int bar( void*); #ifdef __cplusplus // close the extern "C" block, but only if we started it in the first place } #endif </code></pre> <p>And your implementation of them:</p> <pre><code>// entrypoints.cpp // Note: since this is a .cpp file, it's compiled as C++ so we // don't need the #ifdefs around the extern "C" #include "entrypoints.h" extern "C" int foo(void) { return 42; } extern "C" int bar( void* p) { return -42; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload