6 ms·
The issue is not developers, but disallowing the patterns is[a-z].*, to[a-z].*, str[a-z].* and others. Why would anyone do this to a programming language? It's
by Aardwolf 4y ago
The issue is not developers, but disallowing the patterns is[a-z].*, to[a-z].*, str[a-z].* and others. Why would anyone do this to a programming language?
It's a stupid decision to reserve those and it ruins the usability of the language by arbitrarily disallowing many common words that have nothing to do with the intended feature. Even if you don't export names like this directly, having the name of your library or company (as prefix for all exported names) start with those common combinations is likely as well, so now you got to avoid certain library or company names.
If this is only since C11, then I'm even more baffled, since I could somewhat see how such thing could happen in the 1970s when there were limits and the language was brand new and not known to be popular, but in 2011 doing this makes no sense whatsoever.
I hope this is limited to C11 and will never happen in C++.
- zokier 4y agoRoot problem is the lack of namespaces in C, making collisions inevitable and painful to deal with
- flohofwoe 4y agoC doesn't even need namespaces for this, a simple stdc_ prefix for stdlib functions and types would also work (see C23 stdbit.h, I hope this won't be an outlier).
- im3w1l 4y agoWith proper namespaces you can import stuff so you don't have to prefix with the namespace every time.
- flohofwoe 4y agoYes, but we can't simply port C++ namespaces over because this requires symbol name mangling. C could be using 'namespace prefixes' instead with something like 'usingprefix stdc_', this wouldn't require changes to the symbol format, and would provide most of the features of C++ namespaces.
- int_19h 4y agoThat gets very ugly very quick for something as basic as e.g. memcpy or strcmp.
- kevin_thibedeau 4y agoC23 technically has to support namespaces for attributes. It'll be interesting to see if they get adopted into the core language at some point.
- layer8 4y agoWhat else should they reserve in order to be able to introduce new identifiers? The alternative would be that new functions would have to look like __std_c__strfoo().
- Aardwolf 4y agoThey could: -use more obscure letter combinations than "is", "to" and "str" which are very common beginnings of words. How do "is", "to" and "str" help anyway if they want to add functionality that has no sensible name starting with those? -use two underscores at the beginning since as per the article that is already reserved -use stdc_ as prefix
- codeflo 4y agoOr introduce them as __newfunction for the linker, but have a new optional header file that #defines the short name. That’s the route that was chosen for C99’s _Bool/bool (there it was a typedef), and it worked well AFAIK.
- layer8 4y agoThe drawback of the macro solution is that it also disables those names for static symbols and struct members etc. when the header is included. For bool this was okay as it was intended as an opt-in keyword and the header was a new one, but doing that for all functions and in existing headers would potentially break more code.
- pmontra 4y agoI really hate leading underscores, in every language. stc_ or similar prefixes is the way to go.
- int_19h 4y agoStuff like "isalpha", "tolower", and "strlen" long predates standardization of C, so they had to work with what they already had.