In article <ct**********@malatesta.hpl.hp.com>, Chris Dollin <ke**@hpl.hp.com> writes:
ben wrote:
an algorithm book i'm reading talks about the connectivity
problem/algorithm.
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.
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:
are we talking about typedefs maybe? or something else?
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
mi************@microfocus.com
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)