Programming Puzzle

A

Alex Monjushko

In comp.lang.c Ioannis Vranos said:
Julie wrote:
Actually defined in another compilation unit.

Not necessarily. Consider the following, in the same translation unit.

static int a = 42;

extern int a; /* deceptive use of 'extern' */
 
K

Keith Thompson

This is posted only to comp.lang.c++, which I don't regularly follow.

Julie said:
Ioannis Vranos wrote: [...]
The C++ standard says: [...]
"A variable is introduced by the declaration of an object. The
variable's name denotes the object."

Fine -- but what that is saying is that when you create an object, you also
introduce a variable. The opposite is not necessarily true: introducing a
variable does *NOT* imply the declaration of an object.

The first occurence of "variable" in the above quotation from the
standard is in italics. That means it's the definition of the word
"variable", which implies that it's exclusive, i.e., that anything not
introduced by the declaration of an object is not a variable.

That may or may not match the common usage of the term, but if that's
what the standard says it seems appropriate to stick to that
definition.

(The C standard, on the other hand, doesn't define the word
"variable", which is why I dropped comp.lang.c from the Newsgroups
header.)
 
A

Alex Monjushko

In comp.lang.c Ioannis Vranos said:
Alex Monjushko wrote:

As I had said for this one later in the message:
"extern int k; means that it is defined elsewhere (in general)"

"Elsewhere" is technically correct, but it is a little vague in light
of your initial reference to separate translation units.
 
J

Julie

Keith said:
This is posted only to comp.lang.c++, which I don't regularly follow.

Julie said:
Ioannis Vranos wrote: [...]
The C++ standard says: [...]
"A variable is introduced by the declaration of an object. The
variable's name denotes the object."

Fine -- but what that is saying is that when you create an object, you also
introduce a variable. The opposite is not necessarily true: introducing a
variable does *NOT* imply the declaration of an object.

The first occurence of "variable" in the above quotation from the
standard is in italics. That means it's the definition of the word
"variable", which implies that it's exclusive, i.e., that anything not
introduced by the declaration of an object is not a variable.

You may want to research predicate logic.
That may or may not match the common usage of the term, but if that's
what the standard says it seems appropriate to stick to that
definition.

(The C standard, on the other hand, doesn't define the word
"variable", which is why I dropped comp.lang.c from the Newsgroups
header.)

Again, this discussion doesn't have to limit itself to what is or is not
included in any standard. This discussion is about languages, in a forum about
languages (comp.lang.c*), as defined about standards. Variable discussions in
comp.std.c may be inappropriate, here in comp.lang.c, it is perfectly
appropriate -- I've re-added the newsgroup to this reply.
 
I

Ioannis Vranos

Julie said:
Again, this discussion doesn't have to limit itself to what is or is not
included in any standard. This discussion is about languages, in a forum about
languages (comp.lang.c*), as defined about standards. Variable discussions in
comp.std.c may be inappropriate, here in comp.lang.c, it is perfectly
appropriate -- I've re-added the newsgroup to this reply.


Yes it is about the language as defined by the standard, so we should be
better stick to the terminology of the standard, if for not other reason
to be able to understand one another.

clc on the other hand is another language so by adding other languages
newsgroups can only add more confusion.






Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
 
I

Ioannis Vranos

Ioannis said:
Yes it is about the language as defined by the standard, so we should be
better stick to the terminology of the standard, if for not other reason
to be able to understand one another.

clc on the other hand is another language

newsgroup


so by adding other languages
newsgroups can only add more confusion.






Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
 
J

Julie

Ioannis said:
No it says that you declare an object by using a variable. So when you
"declare" a variable in essence you declare an object.

It doesn't say that or infer that at all. Research predicate logic. You can't
assume the reverse of an inference is true.

Specifically:

'declaration of an object' implies 'variable is introduced' (always true)

cannot be reversed to:

'variable is introduced' implies 'declaration of an object' (conditionally
true)
If that is the extent of what is discussed in the standard, then the short of
it is that the standard does not define what a variable is.

It does. A variable (its name) denotes an object.
"An object is a region of storage. [Note: A function is not an object,
regardless of whether or not it occupies storage in the way that objects
do. ] An object is created by a definition (3.1), by a new-expression
(5.3.4) or by the implementation (12.2) when needed."


Seems like it isn't complete to me. Either the other ways (C-style?) to
instanciate an 'object' are either implied or just plain left out. Consider
the differences between:

int i; // created by a definition

int * j = new int; // by a new-expression

extern int k; // by the implementation

Actually defined in another compilation unit.

So what? I was giving an example of the something 'created ... by the
implementation', presuming that k is part of the implementation.
In the above cases we have:

int i;

i is a variable that denotes an object.

int *j=new int;

j is a variable that denotes an int * object, that is the pointer itself.

The new int that is created in the free store is another object, not
denoted by a variable, since it is not created by a variable declaration.

extern int k; means that it is defined elsewhere (in general) and the
"int i" case applies for the definition.

The malloc() situation is the same with the new int situation.

Not the same, but similar, and *not* included in the standard text that you
quoted. That was my point -- the standard text is incomplete, or your
quote/reference is.
 
I

Ioannis Vranos

Julie said:
It doesn't say that or infer that at all. Research predicate logic. You can't
assume the reverse of an inference is true.

Specifically:

'declaration of an object' implies 'variable is introduced' (always true)

cannot be reversed to:

'variable is introduced' implies 'declaration of an object' (conditionally
true)



Ok. You may continue wasting your energy in endless discussions. :)



Not the same, but similar, and *not* included in the standard text that you
quoted. That was my point -- the standard text is incomplete, or your
quote/reference is.



What do you mean not included. It is the same case with operator new.






Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
 
K

Keith Thompson

Julie said:
Keith said:
This is posted only to comp.lang.c++, which I don't regularly follow.

Julie said:
Ioannis Vranos wrote: [...]
The C++ standard says: [...]
"A variable is introduced by the declaration of an object. The
variable's name denotes the object."

Fine -- but what that is saying is that when you create an
object, you also introduce a variable. The opposite is not
necessarily true: introducing a variable does *NOT* imply the
declaration of an object.

The first occurence of "variable" in the above quotation from the
standard is in italics. That means it's the definition of the word
"variable", which implies that it's exclusive, i.e., that anything not
introduced by the declaration of an object is not a variable.

You may want to research predicate logic.

When a word is being formally defined, different rules apply.

In most contexts, the statement that

A variable is introduced by the declaration of an object.

would leave open the possibility that variables could be introduced by
other means. But since the word "variable" is in italics, the above
sentence is intended to be a definition. If a variable can be
introduced by means other than the declaration of an object, I'd say
it's a very poor definition.

Then again, C++ 1.3p2 says:

Terms that are used only in a small portion of this International
Standard are defined where they are used and italicized where they
are defined.

The term "variable" isn't used "only in a small portion" of the
standard. Perhaps the quoted sentence isn't intended to be a
definition (but then I can't imagine why "variable" is in italics).

Perhaps this is a question for comp.std.c++.

[...]
Again, this discussion doesn't have to limit itself to what is or is
not included in any standard. This discussion is about languages,
in a forum about languages (comp.lang.c*), as defined about
standards. Variable discussions in comp.std.c may be inappropriate,
here in comp.lang.c, it is perfectly appropriate -- I've re-added
the newsgroup to this reply.

This sub-branch of the discussion is specifically about the C++
standard's definition of the word "variable"; it's off topic in
comp.lang.c.
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top