13

It looks like nesting extern "C" is legal. For example:

extern "C" extern "C" void foo();

The second extern "C" is essentially ignored. Is that guaranteed by the C++ standard? Where?

Rakete1111
  • 47,013
  • 16
  • 123
  • 162
calvin
  • 567
  • 4
  • 16

1 Answers1

27

Yes, but it's actually the first extern "C" that's ignored. To quote the standard [dcl.link]:

Linkage specifications nest. When linkage specifications nest, the innermost one determines the language linkage.

Dr. Gut
  • 2,053
  • 7
  • 26
calvin
  • 567
  • 4
  • 16
  • you beat me to it ;) – Rob Jan 04 '18 at 16:47
  • 1
    Sorry, I answered my own question. :) I need the reputation! Got tired of not being able to vote or comment. – calvin Jan 04 '18 at 16:56
  • 1
    ROFL! Good for you! – Rob Jan 04 '18 at 16:59
  • 2
    @orochryden In that case, you can post the answer at the same time, as the question. There should be an additional box at the bottom of the question filling page, for the answer. – Algirdas Preidžius Jan 04 '18 at 17:20
  • Damn. What should I do with this info? –  Jan 04 '18 at 19:50
  • 1
    @Ashe the human If by "info" you mean the answer I posted, then maybe I can explain the motivation for the question: I was using a preprocessor macro in a way that led to a nested extern "C" and I was curious if that's actually legal. – calvin Jan 04 '18 at 20:49