top | item 39040649

(no title)

isomorphic- | 2 years ago

The C specification mandates that new keywords use _Keyword naming conventions to ensure backwards compatability by not overriding potentially existing identifiers in codebases. That is why the C specification has reserved identifiers that begin with an underscore and either an uppercase letter or another underscore.

Typically, a <stdkeyword.h> header is included that contain macros to provide the lowercased variants. I.E., this is how _Bool was implemented; <stdbool.h> provides the lowercased `bool` variant.

discuss

order

eps|2 years ago

C23 is scheduled to promote bool, alignof & co. to keywords, so the concern for using _Xxx keywords is recognized by the committee. They introduce _Xxx keywords, sometimes alias them to lowercase versions with macros and let this age. Then, some time after, they switch to the "primary spelling", which is how the lowercase versions are referred to.

You can't easily lowercase _Type and _Var, so practically speaking it will take years before these features could be suitable for wide-spread adoption. Hence my original comment - given the friction, is it worth expanding the language this way at all then?

lifthrasiir|2 years ago

_Bool etc. came with convenience macros defined from <stdbool.h> and so on, but _Generic never did, suggesting that the underscored version was meant to stay forever that way. (Otherwise it should have been named as something like _Generic_switch and later renamed to generic_switch...) Maybe _Type and _Var are similarily intended.