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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jason20005

    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?
  • Richard Heathfield

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

    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

    Comment

    • Bartc

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


      "Jason20005 " <jason20005@gma il.comwrote in message
      news:79d0b2ff-cd84-4121-b418-f219c086db98@h1 g2000prh.google groups.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


      Comment

      • Martin

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

        On Fri, 11 Apr 2008 10:23:05 +0100, Bartc <bc@freeuk.comw rote:
        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

        Comment

        • Mark McIntyre

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

          Martin wrote:
          On Fri, 11 Apr 2008 10:23:05 +0100, Bartc <bc@freeuk.comw rote:
          >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 >

          Comment

          • Chad

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

            On Apr 12, 3:01 pm, Mark McIntyre <markmcint...@s pamcop.netwrote :
            Martin wrote:
            On Fri, 11 Apr 2008 10:23:05 +0100, Bartc <b...@freeuk.co mwrote:
            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.

            Comment

            • Keith Thompson

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

              Mark McIntyre <markmcintyre@s pamcop.netwrite s:
              Martin wrote:
              >On Fri, 11 Apr 2008 10:23:05 +0100, Bartc <bc@freeuk.comw rote:
              >>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_Keit h) <kst-u@mib.org>
              Nokia
              "We must do something. This is something. Therefore, we must do this."
              -- Antony Jay and Jonathan Lynn, "Yes Minister"

              Comment

              Working...