A question about identifiers

C

Chad

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.
 
E

Eric Sosman

Chad said:
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.
 
C

Chad

     (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?
 
B

Ben Bacarisse

Chad said:
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.
 
C

Chad

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


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.




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.
 
C

Chad

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.
 
S

Seebs

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
 
R

Richard Tobin

That is not what "identifier" means. An identifier is, again, a name. It
has nothing to do with values.
[/QUOTE]
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
 
E

Eric Sosman

Chad said:
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.
 
E

Eric Sosman

Seebs said:
[...]
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.
 
J

jacob navia

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.
 
J

John Bode

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.
 
K

Keith Thompson

jacob navia said:
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.
 
N

Nick Keighley

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.

:)
 
D

David Thompson

Chad wrote:

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top