1

3.5 [basic.link] paragraph 8 from N4567 says that

... A type without linkage shall not be used as the type of a variable or function with external linkage unless

  • the entity has C language linkage (7.5), or
  • the entity is declared within an unnamed namespace (7.3.1), or
  • the entity is not odr-used (3.2) or is defined in the same translation unit.

[Note: In other words, a type without linkage contains a class or enumeration that cannot be named outside its translation unit...]

If a type without linkage cannot be named outside its translation unit, how can a declaration in other translation units denote the same type in order to be a part of C language linkage?

  • 1
    [`extern "C"`](http://stackoverflow.com/questions/1041866/in-c-source-what-is-the-effect-of-extern-c) usually does the trick with c++. – πάντα ῥεῖ Feb 12 '16 at 19:19
  • 3
    @EdHeal because the C standard wouldn't talk about 'C language linkage'. – a3f Feb 12 '16 at 19:19
  • @πάνταῥεῖ Did you answer to me, or Ed Heal? – eca2ed291a2f572f66f4a5fcf57511 Feb 12 '16 at 19:27
  • @Il-seobBae I meant to address you. – πάντα ῥεῖ Feb 12 '16 at 19:29
  • @πάνταῥεῖ I understand, in order to be a part of C language linkage, that the type must coincide between two or more declaration with the same name. However, it seems unclear to me how those declarations can denote the same type if one of them use a type without linkage because a type without linkage **literally** means to say that it cannot be named outside its translation unit. Did you really answer to that? – eca2ed291a2f572f66f4a5fcf57511 Feb 12 '16 at 19:38
  • 1
    For C language linkage it's often enough that the memory layout matches. – Cheers and hth. - Alf Feb 12 '16 at 19:47
  • @Cheersandhth.-Alf That makes sense. So it's a compiler's job to check if the memory layout matches and the standard never say a word about it(even about types), am I right? – eca2ed291a2f572f66f4a5fcf57511 Feb 12 '16 at 20:03
  • @Il-seobBae: Ideally it would be that way. But the tool to check memory layout compatibility is ... types. With C++ linkage things, as a matter of in-practice tool usage, the compiler generally produces mangled names that somehow encode the type names, so that the linker can check that they match. But even this scheme does not catch all type mismatches, and for a C linkage function there is no such mangling. So it's up to the programmer. – Cheers and hth. - Alf Feb 12 '16 at 21:11
  • @Cheersandhth.-Alf Thanks. – eca2ed291a2f572f66f4a5fcf57511 Feb 13 '16 at 03:32

0 Answers0