473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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

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
Nov 14 '05 #1
7 2988
On Wed, 26 Jan 2005 15:25:31 +0000, ben wrote:
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
Nov 14 '05 #2
ben wrote:
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.

--
Chris "electric hedgehog" Dollin
Nov 14 '05 #3
ben
In article <pa****************************@netactive.co.uk> , Lawrence
Kirby <lk****@netactive.co.uk> wrote:
On Wed, 26 Jan 2005 15:25:31 +0000, ben wrote:

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


i see -- thanks for both of the replies.
Nov 14 '05 #4
ben wrote:
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

Nov 14 '05 #5

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)
Nov 14 '05 #6
Michael Wojcik wrote:

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.


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?).

--
Chris "electric hedgehog" Dollin
Nov 14 '05 #7

In article <ct**********@malatesta.hpl.hp.com>, Chris Dollin <ke**@hpl.hp.com> writes:
Michael Wojcik wrote:

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.

--
Michael Wojcik mi************@microfocus.com

This record comes with a coupon that wins you a trip around the world.
-- Pizzicato Five
Nov 14 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: G Fernandes | last post by:
Hi, can someone tell me what the following words mean as per C/clc: 1) token 2) token sequence 3) scalar variable 4) vector
2
by: THY | last post by:
Hi, I am having some problem, I declare few variable in a public module and use them in the web application. But after that I found that the variable declared in public variable =...
4
by: Friday | last post by:
Being an Old L.A.M.P guy, I beg you to please excuse my ignorance of dot.net (and all things Windows, for that matter). As part of an experiment (to learn enough ASP/VB.net to port a series of ...
4
by: octavio | last post by:
Hello members of the comp.lang.c newsgroup. Please I need you help on the following one. Compiling the simple code I'm getting this error message. Why ? Please what's the correct type of the fb...
6
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why doesn't the global variable "divId" always refer to the element with id="divId"?...
11
by: gg9h0st | last post by:
i saw a code refactorying onload event listener window.onloadListeners=new Array(); window.addOnLoadListener=function(listener) { window.onloadListeners=listener; } why declare the...
3
by: Yansky | last post by:
If I have the following code: var abc; if(!abc){ alert('test'); }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.