Search code examples
c++cenumslinkage

C vs C++ enum linkage with extern "C"


I have a header with only an unscoped enum declared:

foo.h:

#ifndef FOO_BAR_ENUM_H
#define FOO_BAR_ENUM_H

typedef enum Foo {
    Bar,
    BigBar,
    LittleBar,
    MassiveBar
    BarCount
} Foo;

#endif

I use this header from both C and C++. Should it be guarded by an extern "C" block? Including from both compiles fine, but is there a linking difference in this usage that is valid as far as the compiler is concerned but may not be expected from a naive user?


Solution

  • This header is not going to generate any symbols for linkage, hence it is not necessary to guard it with an extern "C" block.