3

In visual studio code compiled successfully with

extern "C"  char Table[256][256]; 

and if I replace the above code with

extern char Table[256][256];

visual studio starts to give me unresolved external errors for Table?

Zahid Nisar
  • 802
  • 4
  • 15
  • 26

1 Answers1

9

These are two unrelated meanings of the keyword extern.

The first one is the language linkage specifier, which makes the variable interoperable with C.

The second one is the storage class specifier, which declares that the variable is defined elsewhere (which it wasn't, hence the "undefined reference" error).

You could actually use both to declare a variable with C linkage that is defined elsewhere:

extern "C" extern char Table[256][256]; 
Quentin
  • 62,093
  • 7
  • 131
  • 191
  • @anatolyg well, only if that's what you need. Just noting that two `extern` keywords can exist on the same declaration. – Quentin Feb 22 '18 at 10:16
  • 5
    `extern "C" extern` a classic from the people who more recently brought us `noexcept(noexcept(...))` and are soon to bring us `requires requires`.... – StoryTeller - Unslander Monica Feb 22 '18 at 10:26
  • 3
    @StoryTeller don't forget about `long long`, template template parameters, and I'm sure we skirted pretty close to `auto auto` ;) – Quentin Feb 22 '18 at 10:31