lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 21/05/2020 00:21, Joseph C. Sible wrote:
On Wed, May 20, 2020 at 4:53 PM Sean Conner <sean@conman.org> wrote:

  It's pretty bad actually.  The following are reserved by C (using the C99
standard and the pattern "*" matches the character set for a valid
identifier):

        The keywords (obviously) (6.4.2)
        any id matching ^_[A-Za-z_]* (7.1.3)
        function matching *[fl] (7.26.1)
        function matching is* or to* (7.26.2)
        macro matching E[0-9A-Z]* (7.26.3)
        macro matchint PRI[a-zX]* or SCN[a-zX]* (7.26.4)
        macro matchint LC_[A-Z]* (7.26.5)
        macro matching SIG[A-Z]* or SIG_[A-Z]* (7.26.6)
        typedef matching int* uint* *_t (7.26.8)
        macro matching INT*_MAX INT*_MIN INT*_C UINT*_MAX UINT*_MIN UINT*_C (7.26.8)
        function matching str[a-z]* (7.26.10)
        function matching mem[a-z]* wcs[a-z]* (7.26.11)

  C11 adds the following (using the C11 standard here):

        macro matching ATOMIC[A-Z]* (7.31.8)
        typedef matching atomic_[a-z]* memory_[a-z]* (7.31.8)
        enum matching memory_order_[a-z]* (7.31.8)
        function matching atomic_[a-z]* (7.31.8)
        macro matching TIME_[A-Z]* (7.31.14)
        any id matching cnd_[a-z]* mtx_[a-z]* thrd_[a-z]* tss_[a-z]* (7.31.15)

  POSIX might carve out more, but that's left as an exercise to the reader.

  -spc

It's not good, but it's also not quite as bad as you make it sound.
Most of those are only reserved when a certain header is included, and
even then, it's not as broad as you wrote it out to be. In particular,
7.26.1 lists nine specific names, and says that those same nine names
followed by a single 'f' or 'l' are also reserved, not everything that
happens to end with an 'f' or 'l', and 7.26.8 only reserves int*_t and
uint*_t, not all of int*, uint*, and *_t.

Joseph C. Sible


I think you are wrong when you say that those identifiers are reserved only when a specific header is included.

C99 draft N1256 under section 7.26 states:

"All external names described below are reserved no matter what headers are included by the program."

And then goes on with the enumeration of all that mess.

<rant>

But my point was that there is no sane logic behind what one must remember not to use to avoid a clash. That's a relic of the past, from a language design POV. The programmer should not be forced to remember such an incoherent set of information. A programmer's memory is a much scarcer and expensive resource than program memory!

The fun fact is that C is /not/ a terrible language IMO, and it could be greatly improved if it could evolve breaking some connections with its past and cleaning some old cruft.

C++ tried it, but it overdid it. C++ could be a nice language if it weren't for the fact that it is... not a single language! It's so huge that few people know it extensively in its latest version. You could write two C++ programs using a widely disjoint set of features that you could mistake them for programs written in different languages!


</rant>


Cheers!

-- Lorenzo