Re: Why C dont allow the name of a variable start with a digit?



On Apr 10, 9:59 pm, Richard Heathfield <r...@xxxxxxxxxxxxxxx> wrote:
Jason20005 said:

Dear all,

Why C and some of other languages dont allow the name of a variable
start with a digit?

Assume C *did* allow it. What should the output of this program be?

#include <stdio.h>

int main(void)
{
  int 42 = 6;

If C allowed digits at the beginning of an identifier, the above
program could obviously not be the interface the feature by any
reasonable stretch.

Someone sane would have to consider that requirement and come up with
a way of extending the language to support it.

Common Lisp allows arbitrary symbols in identifiers. Not all possible
identifiers can simply be written flat out, however. An escape
notation may have to be used to express some of them. For instance, a
symbol whose name is the digits 12345 would not just be written 12345,
because a token of all-digits is considered an integer literal.
However, only unescaped digits have the meaning of ``digit''. So
escaping just one of the digits makes it into a symbol: \12345, or
1\2345 et cetera, because in all these instances, the token is no
longer made up entirely of digits. Sequences of two or more characters
can be escaped as a group with vertical bars, rather than individually
with the backslash: |1|2345 or just |12345|. Most Lispers would write
it as |12345|, and that's probably how most Lisp would print the
symbol whose name is the string "12345".

A C dialect that allows arbitrary characters in symbols could also
make use of some such escaping convention, without breaking
compatibility.
.



Relevant Pages

  • Re: coderwiki.com is starting and needs you!
    ... PS Or you could have whitespace as identifiers. ... sense (regardless of alphabet); I don't know of any alphabet that uses ... digits in words; admittedly in Japanese and perhaps Chinese the traditional ... for the sake of this argument it is no different from writing "one" instead ...
    (microsoft.public.vc.stl)
  • Re: Whats the legal state of @ character in identifiers?
    ... Whats the legal state of $ character in identifiers? ... at, hash, and dollar) along with letters and non-leading digits. ... So the original question was actually quite a reasonable one. ... It'd be nice if you could wrap identifiers in a cartouche. ...
    (comp.lang.c)
  • Re: Creating custom Primary Key in SQL Server 2005
    ... university uses the scheme for identifiers as: ... digits for the year, followed by 2 digits for the # of the grant ...
    (comp.databases.ms-sqlserver)
  • Re: Creating custom Primary Key in SQL Server 2005
    ... university uses the scheme for identifiers as: ... digits for the year, followed by 2 digits for the # of the grant ...
    (comp.databases.ms-sqlserver)
  • Re: find and regular expresions
    ... Keith Thompson writes: ... > since the '*'s match any sequence of arbitrary characters, ... > digits. ...
    (comp.unix.shell)

Loading