468,315 Members | 1,388 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,315 developers. It's quick & easy.

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

Dear all,

Why C and some of other languages dont allow the name of a variable
start with a digit?
Apr 11 '08 #1
6 1417
Chris McDonald said:

<snip>
>
The question was actually about *starting* with a digit,
which doesn't necessarily imply consisting *only* of digits.
Yes, I know, but I figured (correctly, as it turns out) that using an
all-digit example would bring the point home to the OP very quickly.
But what about: long int 42L = 6;
0X0 also springs to mind.

Forgive me - this is supposed to be a non-commercial channel.

0x20.

There - that's better.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Apr 11 '08 #2

"Jason20005" <ja********@gmail.comwrote in message
news:79**********************************@h1g2000p rh.googlegroups.com...
Dear all,

Why C and some of other languages dont allow the name of a variable
start with a digit?
It's been explained there could be ambiguity between integer constants and
variables.

It might have been feasible where there was no ambiguity (so 0XABC must be a
constant, but 0XABG must an identifier), but it's unsatisfactory. Some other
way of distinguishing constants and identifiers would be needed, and this
would offset some advantage of starting with a digit.

More useful (to me anyway) would have been the ability to use $ in an
identifier (available on some Cs but not standard). Then it could have been
used in place of _, which is difficult to see and can be confused with __
and ___.

--
Bart
Apr 11 '08 #3
On Fri, 11 Apr 2008 10:23:05 +0100, Bartc <bc@freeuk.comwrote:
More useful (to me anyway) would have been the ability to use $ in an
identifier
Indeed. VAX/VMS's DCL allowed dollar-signs, e.g. F$SEVERITY.

--
Martin

Apr 11 '08 #4
Martin wrote:
On Fri, 11 Apr 2008 10:23:05 +0100, Bartc <bc@freeuk.comwrote:
>More useful (to me anyway) would have been the ability to use $ in an
identifier

Indeed. VAX/VMS's DCL allowed dollar-signs, e.g. F$SEVERITY.
Still does allow it. So does VaxC if I recall correctly.

--
Mark McIntyre

CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
Jun 27 '08 #5
On Apr 12, 3:01*pm, Mark McIntyre <markmcint...@spamcop.netwrote:
Martin wrote:
On Fri, 11 Apr 2008 10:23:05 +0100, Bartc <b...@freeuk.comwrote:
More useful (to me anyway) would have been the ability to use $ in an
identifier
Indeed. VAX/VMS's DCL allowed dollar-signs, e.g. F$SEVERITY.

Still does allow it. So does VaxC if I recall correctly.

--

I thought VMS was the actual operating system and that the VAX was the
corresponding hardware. I vaguely remember one of the labs at HP
having FreeBSD running on a VAX.
Jun 27 '08 #6
Mark McIntyre <ma**********@spamcop.netwrites:
Martin wrote:
>On Fri, 11 Apr 2008 10:23:05 +0100, Bartc <bc@freeuk.comwrote:
>>More useful (to me anyway) would have been the ability to use $ in an
identifier

Indeed. VAX/VMS's DCL allowed dollar-signs, e.g. F$SEVERITY.

Still does allow it. So does VaxC if I recall correctly.
Last time I used it, yes.

Whether DCL allows dollar signs isn't particularly relevant; that's
the command language, equivalent to a shell on Unix-like systems. But
the VMS (now OpenVMS) dialect(s) of C does allow dollar signs in
identifiers, used mostly for calling native system routines that have
dollar signs in their names. gcc also supports this extension.

(The two major C compilers for VAX/VMS are VAXC and DECC; the latter
is also supported on Alpha/VMS.)

Of course this is non-standard.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ravi Tallury | last post: by
10 posts views Thread by David Casey | last post: by
2 posts views Thread by yahalom | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.