0

I can see that there is a new keyword type 'attributes' in C23.

Some of it, like [[deprecated]] were used in C11+GNU __attribute__((deprecated)).

I looks like a great update.

I wonder why a usefull keyword as __attribute__((weak)) is not part of the update.

Is this keyword not appreciated by the standard community?

Guillaume D
  • 2,202
  • 2
  • 10
  • 37
  • One thing that comes to mind is because it's not portable. It's not "standard". There are compilers and platforms which do not support it. The other thing is that maybe no one proposed it. – KamilCuk Nov 03 '22 at 16:12
  • why is it not standard? i mean deprecated was not standard, and now, deprecated is part of the standard (ISO). so why not 'weak'? – Guillaume D Nov 03 '22 at 16:14
  • 4
    Linking (aside from translation-unit-level internal/external/no linkage) is not standardized by C at all. – user17732522 Nov 03 '22 at 16:14
  • The page you linked says "Only the following attributes are defined by the C standard [...]", and "weak" is not on the list it gives. So your reference already says that yes, the *standard* attributes approved by the committee do not include "weak". But that does not mean that some implementations can't or won't provide such an attribute. The standard intentionally leaves room for implementation-defined attributes. – John Bollinger Nov 03 '22 at 16:15
  • the question is not "has is been selected?" but "why not include it?" – Guillaume D Nov 03 '22 at 16:16
  • "Linking (aside from per-translation-unit internal/external/no linkage) is not standardized by C at all." makes sense. So maybe the real question underneath is "why linkage is it not standardized?" – Guillaume D Nov 03 '22 at 16:18
  • 2
    @GuillaumeD If mandatory it would impose a lot of requirements on implementations that they might not need. You can have C implementations that don't even have dynamic linking. And current implementations have significant differences in how they handle it (compare e.g. Windows vs Linux). It is just out-of-scope of the standard. – user17732522 Nov 03 '22 at 16:27
  • @GuillaumeD ...because it's not portable (see very first comment), and frankly, none of the language's business how the OS (!) does linking? – DevSolar Nov 03 '22 at 16:27
  • After 5 anwers telling me that linking is *not* portable, I now think that linking is *not* portable :D – Guillaume D Nov 03 '22 at 16:33
  • 2
    Not only are the details of linking not portable, but the whole idea of weak symbols conflicts with C's one-definition rule: "If an identifier declared with external linkage is used in an expression [...], somewhere in the entire program there shall be ***exactly one*** external definition for the identifier" (C17, 6.9/5; emphasis added). ELF can perhaps handwave around that, but I think it's cleaner to just say that support for weak symbols is an extension, in which case *of course* it is not directly supported or acknowledged by the language spec. – John Bollinger Nov 03 '22 at 18:54

0 Answers0