A question about identifiers

Discussion in 'C Programming' started by Chad, Nov 23, 2009.

  1. Chad

    Chad Guest

    Given the following C program...

    int main(void)
    {
    int a;
    a = 6;

    return 0;
    }

    Is 6 an identifier? If so, does it identify the object with the actual
    value? In this case, the actual value on my system would be 0x00000006.
     
    Chad, Nov 23, 2009
    #1
    1. Advertising

  2. Chad

    Eric Sosman Guest

    Chad wrote:
    > Given the following C program...
    >
    > int main(void)
    > {
    > int a;
    > a = 6;
    >
    > return 0;
    > }
    >
    > Is 6 an identifier? If so, does it identify the object with the actual
    > value? In this case, the actual value on my system would be 0x00000006.


    (1) No. (2) From "if false," all conclusions follow.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Nov 23, 2009
    #2
    1. Advertising

  3. Chad

    Chad Guest

    On Nov 22, 6:10 pm, Eric Sosman <> wrote:
    > Chad wrote:
    > > Given the following C program...

    >
    > > int main(void)
    > > {
    > >   int a;
    > >   a = 6;

    >
    > >   return 0;
    > > }

    >
    > > Is 6 an identifier? If so, does it identify the object with the actual
    > > value? In this case, the actual value on my system would be 0x00000006.

    >
    >      (1) No.  (2) From "if false," all conclusions follow.
    >


    Perhaps I'm over complicating this, but doesn't 6 represent something?
    Like maybe an object? Here is what I mean. Let's say I have the
    following sequence of C code...

    char *p;
    p = malloc(6);
    free(p);

    Doesn't 6 have to represent or identify something in order for malloc
    () to allocate the appropriate space?
     
    Chad, Nov 23, 2009
    #3
  4. Chad <> writes:

    > On Nov 22, 6:10 pm, Eric Sosman <> wrote:
    >> Chad wrote:
    >> > Given the following C program...

    >>
    >> > int main(void)
    >> > {
    >> >   int a;
    >> >   a = 6;

    >>
    >> >   return 0;
    >> > }

    >>
    >> > Is 6 an identifier? If so, does it identify the object with the actual
    >> > value? In this case, the actual value on my system would be 0x00000006.

    >>
    >>      (1) No.  (2) From "if false," all conclusions follow.
    >>

    >
    > Perhaps I'm over complicating this, but doesn't 6 represent
    > something?


    Yes, it represents 6. I think you are over complicating it.

    > Like maybe an object?


    No, object has a well-defined meaning when talking about C. An object
    (in C) is a region of storage. It is made up of bits that can be used
    to represent values.

    > Here is what I mean. Let's say I have the
    > following sequence of C code...
    >
    > char *p;
    > p = malloc(6);
    > free(p);
    >
    > Doesn't 6 have to represent or identify something in order for malloc
    > () to allocate the appropriate space?


    If you want to names things, p is an identifier that names an object.
    6 is an integer constant the represents 6. It is part of an
    expression statement (p = malloc(6);) the effect of which is to
    allocate another object with dynamic lifetime and store a pointer to
    this new object in p.

    --
    Ben.
     
    Ben Bacarisse, Nov 23, 2009
    #4
  5. Chad

    Les Harris Guest

    Chad <> writes:
    > Doesn't 6 have to represent or identify something in order for malloc
    > to allocate the appropriate space?


    Sure, 6 represents '6 bytes'.

    --
    Do they only stand
    By ignorance, is that their happy state,
    The proof of their obedience and their faith?
     
    Les Harris, Nov 23, 2009
    #5
  6. Chad

    Chad Guest

    On Nov 22, 6:42 pm, Ben Bacarisse <> wrote:
    > Chad <> writes:
    > > On Nov 22, 6:10 pm, Eric Sosman <> wrote:
    > >> Chad wrote:
    > >> > Given the following C program...

    >
    > >> > int main(void)
    > >> > {
    > >> >   int a;
    > >> >   a = 6;

    >
    > >> >   return 0;
    > >> > }

    >
    > >> > Is 6 an identifier? If so, does it identify the object with the actual
    > >> > value? In this case, the actual value on my system would be 0x00000006.

    >
    > >>      (1) No.  (2) From "if false," all conclusions follow.

    >
    > > Perhaps I'm over complicating this, but doesn't 6 represent
    > > something?

    >
    > Yes, it represents 6.  I think you are over complicating it.
    >
    > > Like maybe an object?

    >
    > No, object has a well-defined meaning when talking about C.  An object
    > (in C) is a region of storage.  It is made up of bits that can be used
    > to represent values.
    >
    > > Here is what I mean. Let's say I have the
    > > following sequence of C code...

    >
    > > char *p;
    > > p = malloc(6);
    > > free(p);

    >
    > > Doesn't 6 have to represent or identify something in order for malloc
    > > () to allocate the appropriate space?

    >
    > If you want to names things, p is an identifier that names an object.
    > 6 is an integer constant the represents 6.  It is part of an
    > expression statement (p = malloc(6);) the effect of which is to
    > allocate another object with dynamic lifetime and store a pointer to
    > this new object in p.
    >


    Yeah, I guess I like to have things named for me. It helps me when I
    read some of the terse responses to other peoples questions on this
    forum.
     
    Chad, Nov 23, 2009
    #6
  7. Chad

    Chad Guest

    On Nov 22, 7:57 pm, Chad <> wrote:
    > On Nov 22, 6:42 pm, Ben Bacarisse <> wrote:
    >
    >
    >
    > > Chad <> writes:
    > > > On Nov 22, 6:10 pm, Eric Sosman <> wrote:
    > > >> Chad wrote:
    > > >> > Given the following C program...

    >
    > > >> > int main(void)
    > > >> > {
    > > >> >   int a;
    > > >> >   a = 6;

    >
    > > >> >   return 0;
    > > >> > }

    >
    > > >> > Is 6 an identifier? If so, does it identify the object with the actual
    > > >> > value? In this case, the actual value on my system would be 0x00000006.

    >
    > > >>      (1) No.  (2) From "if false," all conclusions follow.

    >
    > > > Perhaps I'm over complicating this, but doesn't 6 represent
    > > > something?

    >
    > > Yes, it represents 6.  I think you are over complicating it.

    >
    > > > Like maybe an object?

    >
    > > No, object has a well-defined meaning when talking about C.  An object
    > > (in C) is a region of storage.  It is made up of bits that can be used
    > > to represent values.

    >
    > > > Here is what I mean. Let's say I have the
    > > > following sequence of C code...

    >
    > > > char *p;
    > > > p = malloc(6);
    > > > free(p);

    >
    > > > Doesn't 6 have to represent or identify something in order for malloc
    > > > () to allocate the appropriate space?

    >
    > > If you want to names things, p is an identifier that names an object.
    > > 6 is an integer constant the represents 6.  It is part of an
    > > expression statement (p = malloc(6);) the effect of which is to
    > > allocate another object with dynamic lifetime and store a pointer to
    > > this new object in p.

    >
    > Yeah, I guess I like to have things named for me. It helps me when I
    > read some of the terse responses to other peoples questions on this
    > forum.


    Hmm... That response sound kind of awkward.
     
    Chad, Nov 23, 2009
    #7
  8. Chad

    Seebs Guest

    On 2009-11-23, Chad <> wrote:
    > Given the following C program...


    > int main(void)
    > {
    > int a;
    > a = 6;
    >
    > return 0;
    > }


    > Is 6 an identifier?


    No.

    An identifier is just a fancy word for a name, and identifiers are things
    which start with an underscore or a letter, followed by underscores, letters,
    and digits.

    > If so, does it identify the object with the actual
    > value? In this case, the actual value on my system would be 0x00000006.


    That is not what "identifier" means. An identifier is, again, a name. It
    has nothing to do with values.

    -s
    --
    Copyright 2009, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
     
    Seebs, Nov 23, 2009
    #8
  9. In article <hed8hn$b7o$-september.org>,
    Richard <> wrote:

    >> That is not what "identifier" means. An identifier is, again, a name. It
    >> has nothing to do with values.


    >Clearly nonsense since it has a very close connection to values : its
    >how people USE those values.
    >
    >int i =j;
    >
    >Are you saying j does not have a value?


    I think you're reading to much into "nothing to do with values". Of
    course j has a value, but presumably the OP is concerned with the
    technical meaning of the terms, otherwise he wouldn't be asking
    whether 6 is an identifier. From that point of view, j is an
    identifier denoting an object whose value is 6. Not all identifiers
    denote objects, so they don't all have values (a label for example).

    -- Richard
    --
    Please remember to mention me / in tapes you leave behind.
     
    Richard Tobin, Nov 23, 2009
    #9
  10. Chad

    Eric Sosman Guest

    Chad wrote:
    > On Nov 22, 6:10 pm, Eric Sosman <> wrote:
    >> Chad wrote:
    >>> Given the following C program...
    >>> int main(void)
    >>> {
    >>> int a;
    >>> a = 6;
    >>> return 0;
    >>> }
    >>> Is 6 an identifier? If so, does it identify the object with the actual
    >>> value? In this case, the actual value on my system would be 0x00000006.

    >> (1) No. (2) From "if false," all conclusions follow.
    >>

    >
    > Perhaps I'm over complicating this, but doesn't 6 represent something?


    Yes: It represents a value. But it's still not an identifier.

    > Like maybe an object?


    No. If there were an object, you could form a pointer to that
    object and pass the pointer around. But you can't: The 6 merely
    denotes a value, and says nothing at all about how that value comes
    to life in the program.

    Some implementations may actually allocate an int-sized piece
    of memory containing the value 6, and read from that "invisible
    object" when the value is needed -- but that's just the system's
    own way of getting things done, not an implication that there's an
    actual object floating around. Other implementations may have a
    more economical way of generating small integer values, like an
    "immediate operand" taking less than an int's worth of memory,
    so there's not even an int-sized piece of storage to look at if
    you could peer behind the curtain. You write 6, the implementation
    works some kind of magic, and the value six shows up. That's all.

    > char *p;
    > p = malloc(6);
    > free(p);
    >
    > Doesn't 6 have to represent or identify something in order for malloc
    > () to allocate the appropriate space?


    Yes: 6 represents the value six, with type int. Assuming
    all is well, this value will then be converted to the value six
    with type size_t, and that's what malloc() will receive as an
    argument. The conversion from int to size_t may well happen at
    compile time, so that an int six never even exists at all when
    the program runs. And, as before, this doesn't mean that there's
    a size_t-sized piece of memory somewhere that holds a six; the
    implementation delivers the six to malloc() by whatever means
    it chooses.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Nov 23, 2009
    #10
  11. Chad

    Eric Sosman Guest

    Seebs wrote:
    > [...]
    > An identifier is just a fancy word for a name, and identifiers are things
    > which start with an underscore or a letter, followed by underscores, letters,
    > and digits.


    Note that merely matching the syntax does not qualify a
    source token as an identifier. For example, `break' and `int'
    and `const' are not identifiers.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Nov 23, 2009
    #11
  12. Chad

    jacob navia Guest

    Chad a écrit :
    > Given the following C program...
    >
    > int main(void)
    > {
    > int a;
    > a = 6;
    >
    > return 0;
    > }
    >
    > Is 6 an identifier? If so, does it identify the object with the actual
    > value? In this case, the actual value on my system would be 0x00000006.


    Identifiers are names of values. In *some* sense, a number is some abstract
    thing that can be named in different ways:

    6 arabic numerals
    VI roman
    six english
    seis spanish
    sechs german
    schesch hebrew
    1010 binary base

    All those are "identifiers" of the abstract number. But in C, a numeric
    constant is not an identifier.
     
    jacob navia, Nov 23, 2009
    #12
  13. Chad

    John Bode Guest

    On Nov 22, 7:59 pm, Chad <> wrote:
    > Given the following C program...
    >
    > int main(void)
    > {
    >   int a;
    >   a = 6;
    >
    >   return 0;
    >
    > }
    >
    > Is 6 an identifier? If so, does it identify the object with the actual
    > value? In this case, the actual value on my system would be 0x00000006.


    '6' is an integer constant expression, not an identifier. It cannot
    serve as an lvalue; you can't assign to it, you can't take its
    address, you can't apply operators like ++ or -- to it, etc. Whether
    it's associated with a distinct block of memory is an implementation
    detail; for small values like this, it's probably encoded as an
    immediate operand in the instruction.
     
    John Bode, Nov 23, 2009
    #13
  14. Chad

    Kaz Kylheku Guest

    On 2009-11-23, jacob navia <> wrote:
    > Chad a écrit :
    >> Given the following C program...
    >>
    >> int main(void)
    >> {
    >> int a;
    >> a = 6;
    >>
    >> return 0;
    >> }
    >>
    >> Is 6 an identifier? If so, does it identify the object with the actual
    >> value? In this case, the actual value on my system would be 0x00000006.

    >
    > Identifiers are names of values.


    Sure.

    typedef int iden1;
    stuct ident2;
     
    Kaz Kylheku, Nov 23, 2009
    #14
  15. jacob navia <> writes:
    [...]
    > Identifiers are names of values.

    [...]

    Identifiers are names, but not necessarily of values.

    An identifier is a syntactic construct, a particular kind of token,
    nothing more, nothing less.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Nov 23, 2009
    #15
  16. On 23 Nov, 06:01, Richard <> wrote:
    > Seebs <> writes:
    > > On 2009-11-23, Chad <> wrote:



    > >> Given the following C program...

    >
    > >> int main(void)
    > >> {
    > >>   int a;
    > >>   a = 6;
    > >>   return 0;
    > >> }

    >
    > >> Is 6 an identifier?

    >
    > > No.

    >
    > > An identifier is just a fancy word for a name, and identifiers are things
    > > which start with an underscore or a letter, followed by underscores, letters,
    > > and digits.

    >
    > >> If so, does it identify the object with the actual
    > >> value? In this case, the actual value on my system would be 0x00000006..

    >
    > > That is not what "identifier" means.  An identifier is, again, a name..  It
    > > has nothing to do with values.

    >
    > Clearly nonsense since it has a very close connection to values : its
    > how people USE those values.
    >
    > int i =j;
    >
    > Are you saying j does not have a value?


    you don't initialise it so it doesn't have a value


    > Don't try to be too clever : it ends up in language wars.


    :)
     
    Nick Keighley, Nov 24, 2009
    #16
  17. On Mon, 23 Nov 2009 09:15:18 -0500, Eric Sosman
    <> wrote:

    > Chad wrote:


    > > Perhaps I'm over complicating this, but doesn't 6 represent something?


    > > Like maybe an object?

    >
    > No. If there were an object, you could form a pointer to that
    > object and pass the pointer around. But you can't: The 6 merely
    > denotes a value, and says nothing at all about how that value comes
    > to life in the program.
    >

    In C you can't form a pointer to an object with register storage
    class. On most matchines ff it actually is in a register, it is not
    possible to have a pointer to it (there are a few exceptions). But C
    makes the prohibition uniform; even if the compiler chooses to put a
    'register' object in memory, you still can't take & of it.

    The defining characteristic of objects is storage. For objects that
    are mutable, you can observe change in state i.e. contents. But C also
    has const objects, which you can't change. In a philosophical sense,
    const register objects aren't distinguishable from values.

    > Some implementations may actually allocate an int-sized piece
    > of memory containing the value 6, and read from that "invisible
    > object" when the value is needed -- but that's just the system's
    > own way of getting things done, not an implication that there's an
    > actual object floating around. Other implementations may have a


    I'd say there is not a *C* object. There is a kinda-sorta-object.
    For example, S/360 et seq did this so much that the assembler had
    convenient syntax for it:
    Load R3, =W(123)
    assembles a word of data elsewhere (initially) containing 123, and a
    code instruction (inline) that loads from that word of data to R3.

    > more economical way of generating small integer values, like an
    > "immediate operand" taking less than an int's worth of memory,
    > so there's not even an int-sized piece of storage to look at if
    > you could peer behind the curtain. You write 6, the implementation
    > works some kind of magic, and the value six shows up. That's all.
    >

    And sometimes two (or perhaps more) pieces, e.g.
    LoadHI R3, 0x12
    LoadLO R3, 0x3456
    to give you 0x123456 in the register without any contiguous storage
    containing 0x123456 (in whatever endianness applies).

    And sometimes no storage at all. Quite a few machines have 'hardcoded
    zero' as one of the register choices, and I've heard of some that have
    a few others like -1 (equivalently ~0 in 2sC as is now most common).

    The PDP-8 had microcoded* operate instructions that could generate a
    small and rather eclectic set of values with no data word (which was
    precious; you got at most 125 in current page and 128 minus
    reservations in zero page) and no data fetch (also precious).
    6 happens to be among them, using CLA INC STL RTL .
    I no longer remember the encoding for this (and am not going to bother
    looking it up) but I'm confident it doesn't resemble 6 *at all*.

    (* sort of VLIW style, for extremely small values of large, about
    15-20 years before that terminology came into use)

    <snip rest>
     
    David Thompson, Dec 9, 2009
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. valentin tihomirov

    Advantages of denying keywords as identifiers

    valentin tihomirov, Dec 17, 2004, in forum: VHDL
    Replies:
    8
    Views:
    514
    Mike Treseler
    Dec 28, 2004
  2. Spartanicus
    Replies:
    2
    Views:
    971
    brucie
    May 25, 2004
  3. Replies:
    1
    Views:
    355
    Roedy Green
    Apr 22, 2008
  4. puzzlecracker
    Replies:
    3
    Views:
    272
    mlimber
    Aug 21, 2008
  5. Chad
    Replies:
    9
    Views:
    320
    William Hughes
    May 1, 2010
Loading...

Share This Page