News for hackers. Stuff that matters.
Re:ISO C is increasingly moronic by aliguori on Tuesday December 20, 2011 @04:12PM (#3375182)
I don't agree with your assertion that backwards compatibility isn't important, but I would like to point out that the very fact that C compilers allow you to use identifiers that are in the form _Word means that they are breaking backwards compatibility by introducing new keywords.

Many of the libraries on a typical Linux system (anything glib/gtk based, libxml2, etc.) use _Word extensively.

Re:ISO C is increasingly moronic by breadbox on Tuesday December 20, 2011 @04:23PM (#3375233)
Initial underscore followed by a capital letter is a reserved "namespace" since 1990, as a previous commenter noted. (And for the record, identifiers that begin with two underscores are reserved for use by the implementation, and identifiers followed by a lowercase letter are guaranteed to be unreserved as long as they are file-scoped symbols, and not globally visible.)
Re:ISO C is increasingly moronic by aliguori on Tuesday December 20, 2011 @05:07PM (#3375404)
Yes, I realize this, but since it's only "reserved" in the specification and the compiler doesn't enforce this, there is a massive amount of code that does this today.

The spec could contain, "don't add any bugs into your C programs" but that doesn't magically mean that everyone would write bug free code.

Reserving a namespace and not having a mechanism to enforce it was a massive fail on the part of the standards committee.

Re:ISO C is increasingly moronic by plq on Tuesday December 20, 2011 @06:03PM (#3375599)
> Reserving a namespace and not having a mechanism to enforce it was a massive fail on the part of the standards committee.

How do you expect the compiler to enforce the "identifiers that begin with two underscores are reserved for use by the implementation" rule? Some things just belong in the documentation.

Re:ISO C is increasingly moronic by aliguori on Tuesday December 20, 2011 @08:52PM (#3376048)
If the goal is to allow the introduction of new keywords, then it's fairly simple. Don't parse anything in the form __[a-z0-9$_] as anything but a keyword.

Problem solved. Instead, they did something awkward by trying to carve out namespaces for the stdlib too but quite frequently don't adhere to their own rules.

Re:ISO C is increasingly moronic by gsg on Wednesday December 21, 2011 @02:01AM (#3376646)
The goal is not just to allow for new keywords. Reserved identifiers are also intended to be used in system headers to protect implementation code from the unfortunate effect of user defined symbols.

Go and read your /usr/include/stdio.h (or equivalent). It will be filled with such symbols. Obviously the compiler must lex them exactly as it would unreserved symbols.

This is an unfortunately legacy of C's decision to pass compilation information around by textual inclusion, and isn't really fixable at this point.

Re:ISO C is increasingly moronic by JoshTriplett on Wednesday December 21, 2011 @05:07AM (#3376979)
System headers could use a #pragma _SystemIdentifiers, much like TeX's "makeatletter" and "makeatother" that allow packages to use @ in the name of internal symbols to avoid conflicts.

I do think compilers ought to have warnings for using identifiers in the reserved namespace. Most projects probably wouldn't trip over the ^_[A-Z] reserved space; however, numerous projects would trip over the reservation of any identifier containing two adjacent underscores.

Re:ISO C is increasingly moronic by gsg on Wednesday December 21, 2011 @07:44AM (#3377318)
That would require changing every single existing header that currently contains reserved identifiers. Do you have any idea how much work that is? Even if you could somehow magically enumerate and alter them all - and test them, since the necessary renaming of identifiers in non-system headers might introduce a bug - legacy versions would be floating around for years.

Conceptually a warning is a nice idea, but it just isn't practical.

Re:ISO C is increasingly moronic by JoshTriplett on Wednesday December 21, 2011 @01:36PM (#3378527)
Not necessarily. GCC, at least, avoids showing warnings in system headers unless explicitly requested. So, normally you'd only see warnings about the use of reserved identifiers in your own code.
Re:ISO C is increasingly moronic by TheNewAndy on Wednesday December 21, 2011 @02:04AM (#3376660)
But there are lots of places where these identifiers aren't keywords, and it is valid code (try writing a compliant stdlib without using them).

The problem is that too many people assume that their usage of C is the same as everyone elses. I don't want to be writing a system library and fighting my compiler everytime I put something in the symbol table that isn't in the C spec.

Re:ISO C is increasingly moronic by to3m on Tuesday December 20, 2011 @09:53PM (#3376188)
It's to allow use of any identifiers anywhere, not just keywords, without having to worry about conflicts with the including code.