Re: C objects
From: Stefan Ram (ram_at_zedat.fu-berlin.de)
Date: 08/08/04
- Next message: sathya_me: "Re: Checking the type of a variable with equality operator"
- Previous message: CBFalconer: "Re: stuck on time_t"
- In reply to: RCollins: "Re: C objects"
- Next in thread: RCollins: "Re: C objects"
- Reply: RCollins: "Re: C objects"
- Reply: Keith Thompson: "Re: C objects"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 8 Aug 2004 12:51:24 GMT
RCollins <rcoll@nospam.theriver.com> writes:
>So, by this reasoning, then the 2 functions (in the same source
>file) below:
>void foo(void) {
>int i;
> i = 1;
>}
>void bar(void) {
>int i;
> i = 2;
>}
>define only 1 identifier, that happens to have 2 different
>object locations?
Yes, just let me quote ISO/IEC 9899:1999 (E):
"For each different entity that an identifier designates,
the identifier is visible (i.e., can be used) only
within a region of program text called its scope."
Note the singular "an identifier". "An identifier" (i.e., only
1 identifier) might designate different entities. This is the
wording of ISO/IEC 9899:1999 (E).
Another reason: An identifier is a lexical concept and is
defined as:
(6.4.2.1) identifier:
identifier-nondigit
identifier identifier-nondigit
identifier digit
So by this extensional definition, there exist only one
identifier "i".
>I don't think we're on the same wavelength at all. We're (or, at
>least, I) are not talking about what happens at run-time. We're
>talking about source code (the only part we have any real control
>over).
The source code model does not contain the notion of an
"object". The source code is built of lexical and syntactical
units. An object is part of the execution model, though in
order to interpret (make sense of) the source code, one needs
to mention execution model entities.
>in the simple function:
>void foo(void) {
>int i;
>}
>the identifer i refers to an object of type integer; if I never use
>the variable, or if foo() is explicitly never called, then the
>compiler may choose to optimize it away. But, as far as my (source)
>program is concerned, both foo() and i exist, and refer to somthing
>concrete.
This is not a mere "optimization". The local variables of a
function are created as many times as the function is
activated at run time - otherwise recursion would not work.
So, if a function is not activated, there is not reason to
create activation records.
The identifier "i" refers to an object under the assumption
that the function is currently activated. This is usually
taken for granted, so that one does not mention it. By
recursion, a function may be activated more than once in the
same program instance at the same time. In this case, when one
speaks about "i" one usually is referring to an exemplary i
from all those is existing at the same time.
- Next message: sathya_me: "Re: Checking the type of a variable with equality operator"
- Previous message: CBFalconer: "Re: stuck on time_t"
- In reply to: RCollins: "Re: C objects"
- Next in thread: RCollins: "Re: C objects"
- Reply: RCollins: "Re: C objects"
- Reply: Keith Thompson: "Re: C objects"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|