what is "variable-name-equivalence" in c?

B

ben

hello,

an algorithm book i'm reading talks about the connectivity
problem/algorithm.

it gives a number of examples where the connectivity problem applies to
real life situations (like, the objects may represent computers in a
large network and the pairs represent connections between them)

another real situation example that's given is:

"Still another example arises in certain programming environments where
it is possible to declare two variable names as equivalent. The problem
is to be able to determine whether two given names are equivalent,
after a sequence of such declarations."

what does declaring two variable names as equivalent mean/entail in c?
are we talking about typedefs maybe? or something else?

thanks, ben
 
L

Lawrence Kirby

hello,

an algorithm book i'm reading talks about the connectivity
problem/algorithm.

it gives a number of examples where the connectivity problem applies to
real life situations (like, the objects may represent computers in a
large network and the pairs represent connections between them)

another real situation example that's given is:

"Still another example arises in certain programming environments where
it is possible to declare two variable names as equivalent. The problem
is to be able to determine whether two given names are equivalent,
after a sequence of such declarations."

what does declaring two variable names as equivalent mean/entail in c?

AFAICS C isn't one of the programming "environments" being referred to. It
does't have a direct way of saying that two variable names are
equivalent.
are we talking about typedefs maybe? or something else?

That is a possibility if you are talking about types rather than
variables. Macros are a way of creating something similar for identifiers,
which include but are not limited to variable names.

I think that something like C++'s references are a closer match to the
situation being described. Ask in comp.lang.c++ for more details.

Lawrence
 
C

Chris Dollin

ben said:
an algorithm book i'm reading talks about the connectivity
problem/algorithm.

it gives a number of examples where the connectivity problem applies to
real life situations (like, the objects may represent computers in a
large network and the pairs represent connections between them)

another real situation example that's given is:

"Still another example arises in certain programming environments where
it is possible to declare two variable names as equivalent. The problem
is to be able to determine whether two given names are equivalent,
after a sequence of such declarations."

what does declaring two variable names as equivalent mean/entail in c?

Concept not supported.
are we talking about typedefs maybe? or something else?

Fortran's EQUIVALENCE and stuff in COBOL, I should think.
 
B

ben

Lawrence said:
AFAICS C isn't one of the programming "environments" being referred to. It
does't have a direct way of saying that two variable names are
equivalent.

i see -- thanks for both of the replies.
 
S

sathyashrayan

ben said:
hello,

an algorithm book i'm reading talks about the connectivity
problem/algorithm.

it gives a number of examples where the connectivity problem applies to
real life situations (like, the objects may represent computers in a
large network and the pairs represent connections between them)

another real situation example that's given is:

"Still another example arises in certain programming environments where
it is possible to declare two variable names as equivalent. The problem
is to be able to determine whether two given names are equivalent,
after a sequence of such declarations."

Equivalent in the above contest is that the both variable has a same
value or same variable name? If a variable is in function scope then it
does not prevents you from declaring the same type and same name in the
block scope. Is that what the above quotes text means? Or it is a
compiler programming problem where you have to determine and produce an
error when a variable has been declared two times.

If the OP is more detailed then is a subject of learning.
what does declaring two variable names as equivalent mean/entail in c?
are we talking about typedefs maybe? or something else?

thanks, ben


--
"combination is the heart of chess"

A.Alekhine

Mail to:
sathyashrayan AT gmail DOT com
 
M

Michael Wojcik

Concept not supported.

I think you could argue that unions declare two "variable names as
equivalent", if we take "variable names" in a looser sense than how
the standard uses it. (Actually, that particular phrase doesn't seem
to appear in the the standard, but it clearly has a sense of what a
variable and its name are.)

In that more general sense, if we have:

union {int foo; int bar;} quux;

then "quux.foo" and "quux.bar" are both names for the same region of
storage, ie variable.

However:
Fortran's EQUIVALENCE and stuff in COBOL, I should think.

The "stuff in COBOL" would presumably be the REDEFINES clause of the
data division, which can be applied to an item to indicate that it
occupies the same location as another item:

01 item-1 pic x.
01 item-2 pic x redefines item-1.

Unlike C, which groups such "equivalent names" in a union, COBOL lets
you put a REDEFINES pretty much anywhere in the data division; thus
you can have one item redefining another that appeared pages away,
then a third redefinition somewhere else, and so forth; and in such a
case, the third might actually specify the second as the item it
redefines, so you have a chain of redefinition. That doesn't happen
in C, because the union syntax in effect does implicitly what
REDEFINES does explicitly, so the programmer can't create strange
networks of redefinitions.

That might be what the book was referring to.

--
Michael Wojcik (e-mail address removed)

The surface of the word "profession" is hard and rough, the inside mixed with
poison. It's this that prevents me crossing over. And what is there on the
other side? Only what people longingly refer to as "the other side".
-- Tawada Yoko (trans. Margaret Mitsutani)
 
C

Chris Dollin

Michael said:
I think you could argue that unions declare two "variable names as
equivalent", if we take "variable names" in a looser sense than how
the standard uses it. (Actually, that particular phrase doesn't seem
to appear in the the standard, but it clearly has a sense of what a
variable and its name are.)

In that more general sense, if we have:

union {int foo; int bar;} quux;

then "quux.foo" and "quux.bar" are both names for the same region of
storage, ie variable.

I wondered about mentioning unions. But I don't think they qualify,
because while the store overlaps, it is explicitly undefined what
happens if you write to one element and read from another [unless
at least one of them is unsigned char [], ish, yes?).
 
M

Michael Wojcik

Michael said:
I think you could argue that unions declare two "variable names as
equivalent", if we take "variable names" in a looser sense than how
the standard uses it.

I wondered about mentioning unions. But I don't think they qualify,
because while the store overlaps, it is explicitly undefined what
happens if you write to one element and read from another [unless
at least one of them is unsigned char [], ish, yes?).

That sounds like a reasonable objection, sure. At any rate, the OP's
question doesn't seem to have a satisfactory C answer.

See, that's why it's good to learn a little COBOL: you get exposed
to all sorts of historical weirdness.
 

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
474,183
Messages
2,570,968
Members
47,524
Latest member
ecomwebdesign

Latest Threads

Top