Re: Why C dont allow the name of a variable start with a digit?
- From: Kaz Kylheku <kkylheku@xxxxxxxxx>
- Date: Fri, 11 Apr 2008 17:42:17 -0700 (PDT)
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.
.
- References:
- Why C dont allow the name of a variable start with a digit?
- From: Jason20005
- Re: Why C dont allow the name of a variable start with a digit?
- From: Richard Heathfield
- Why C dont allow the name of a variable start with a digit?
- Prev by Date: Re: How to generate random numbers in C
- Next by Date: Re: is this portable?
- Previous by thread: Re: Why C dont allow the name of a variable start with a digit?
- Next by thread: Re: Why C dont allow the name of a variable start with a digit?
- Index(es):
Relevant Pages
|
Loading