473,325 Members | 2,480 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,325 software developers and data experts.

alias for a variable

Hi Friends,

Can we have a alias of a variable in C.

Like I define an int---
int example;

Now I want another variable that is the alias for the "example". I
meant both example and another variable let say "example2" have the
same memory but we are refrencing with it by two variables.
I need both to be global variables.

I am not talking about call by reference and I can use #define. Am I?

Regards,
Paresh

Feb 15 '07 #1
14 13977
paresh said:
Hi Friends,

Can we have a alias of a variable in C.

Like I define an int---
int example;

Now I want another variable that is the alias for the "example". I
meant both example and another variable let say "example2" have the
same memory but we are refrencing with it by two variables.
Yes, you could use #define, or you could simply point two pointers at
the same object.
I need both to be global variables.
Why on earth would you need to do that?
I am not talking about call by reference
No such thing in C.
and I can use #define.
Yes, you can.
Am I?
Am you what?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 15 '07 #2
On Feb 15, 1:59 am, "paresh" <pareshvarsh...@gmail.comwrote:
Hi Friends,

Can we have a alias of a variable in C.

Like I define an int---
int example;

Now I want another variable that is the alias for the "example". I
meant both example and another variable let say "example2" have the
same memory but we are refrencing with it by two variables.
I need both to be global variables.

I am not talking about call by reference and I can use #define. Am I?

Are you perhaps looking for a union?

Feb 15 '07 #3
On Feb 15, 2:01 pm, "robertwess...@yahoo.com"
<robertwess...@yahoo.comwrote:
On Feb 15, 1:59 am, "paresh" <pareshvarsh...@gmail.comwrote:
Hi Friends,
Can we have a alias of a variable in C.
Like I define an int---
int example;
Now I want another variable that is the alias for the "example". I
meant both example and another variable let say "example2" have the
same memory but we are refrencing with it by two variables.
I need both to be global variables.
I am not talking about call by reference and I can use #define. Am I?

Are you perhaps looking for a union?

No I am not looking for union. Yes the easiast way to do this is
#define.
Is there any other way?

Feb 15 '07 #4
On 15 Feb, 09:51, "paresh" <pareshvarsh...@gmail.comwrote:
On Feb 15, 2:01 pm, "robertwess...@yahoo.com"
<robertwess...@yahoo.comwrote:
On Feb 15, 1:59 am, "paresh" <pareshvarsh...@gmail.comwrote:
Can we have a alias of a variable in C.
Like I define an int---
int example;
Now I want another variable that is the alias for the "example". I
meant both example and another variable let say "example2" have the
same memory but we are refrencing with it by two variables.
I need both to be global variables.
I am not talking about call by reference and I can use #define. Am I?
Are you perhaps looking for a union?

No I am not looking for union. Yes the easiast way to do this is
#define.
Is there any other way
why do you want to do this? What was wrong with Richard's
suggestion to use pointers?

#define and global variables sound like an accident
waiting to happen.
--
Nick Keighley

Feb 15 '07 #5
paresh wrote:
Hi Friends,

Can we have a alias of a variable in C.

Like I define an int---
int example;

Now I want another variable that is the alias for the "example". I
meant both example and another variable let say "example2" have the
same memory but we are refrencing with it by two variables.
I need both to be global variables.
Never mind the answers: the real question is, /why/ do you want to
do this? It looks like a real Asking For Trouble to me. There's
quite enough necessary aliasing in programming already.

--
Chris "electric hedgehog" Dollin
"He's dead, Jim, but not as we know it." Unsaid /Trek/.

Feb 15 '07 #6
On Feb 15, 2:56 pm, Chris Dollin <chris.dol...@hp.comwrote:
paresh wrote:
Hi Friends,
Can we have a alias of a variable in C.
Like I define an int---
int example;
Now I want another variable that is the alias for the "example". I
meant both example and another variable let say "example2" have the
same memory but we are refrencing with it by two variables.
I need both to be global variables.

Never mind the answers: the real question is, /why/ do you want to
do this? It looks like a real Asking For Trouble to me. There's
quite enough necessary aliasing in programming already.

--
Chris "electric hedgehog" Dollin
"He's dead, Jim, but not as we know it." Unsaid /Trek/.

There is already a large chuck of code, I want to use that.
There is a sturcture(quite large) that is used at two different
location.
I dont want to waste memory(embedded device I dont have much) so i am
trying to use the same sturcture by using extern. If I use pointer I
have to
do a lot of mechanical changes(stuct to pointer to stuct) in one
module.

Regards

Feb 15 '07 #7
On 15 Feb, 10:13, "paresh" <pareshvarsh...@gmail.comwrote:
On Feb 15, 2:56 pm, Chris Dollin <chris.dol...@hp.comwrote:
paresh wrote:
Can we have a alias of a variable in C.
Like I define an int---
int example;
Now I want another variable that is the alias for the "example". I
meant both example and another variable let say "example2" have the
same memory but we are refrencing with it by two variables.
I need both to be global variables.
Never mind the answers: the real question is, /why/ do you want to
do this? It looks like a real Asking For Trouble to me. There's
quite enough necessary aliasing in programming already.
--
Chris "electric hedgehog" Dollin
"He's dead, Jim, but not as we know it." Unsaid /Trek/.
you should normally trim sigs

There is already a large chuck of code, I want to use that.
There is a sturcture(quite large) that is used at two different
location.
I dont want to waste memory(embedded device I dont have much) so i am
trying to use the same sturcture by using extern. If I use pointer I
have to
do a lot of mechanical changes(stuct to pointer to stuct) in one
module.
I'd (probably) bite the bullet and do the global edit(s).

my_struct. =my_struct->
&my_struct =my_struct
--
Nick Keighley


Feb 15 '07 #8
paresh wrote:
On Feb 15, 2:56 pm, Chris Dollin <chris.dol...@hp.comwrote:
>paresh wrote:
Hi Friends,
Can we have a alias of a variable in C.
Like I define an int---
int example;
Now I want another variable that is the alias for the "example". I
meant both example and another variable let say "example2" have the
same memory but we are refrencing with it by two variables.
I need both to be global variables.

Never mind the answers: the real question is, /why/ do you want to
do this? It looks like a real Asking For Trouble to me. There's
quite enough necessary aliasing in programming already.

--
Chris "electric hedgehog" Dollin
"He's dead, Jim, but not as we know it." Unsaid /Trek/.

There is already a large chuck of code, I want to use that.
There is a sturcture(quite large) that is used at two different
location.
I dont want to waste memory(embedded device I dont have much) so i am
trying to use the same sturcture by using extern. If I use pointer I
have to
do a lot of mechanical changes(stuct to pointer to stuct) in one
module.
Either the two structures /should/ be different objects, in which
case leave well alone, or they should be the same object (so how
did /that/ happen?), in which case delete one of them from the
code -- you will have to do that anyway, if you want to save space --
and change all the references to it to refer to the other one.

I don't see why you want to mess around with aliasing when what
you want to is a cut-and-rename.
If I use pointer I have to
do a lot of mechanical changes(stuct to pointer to stuct) in one
module.
Well, yes, but that looks like a one-liner

ENTER gs/name./ptrName->/ RETURN

or however your local editor handles a global substitute.

--
Chris "electric hedgehog" Dollin
A rock is not a fact. A rock is a rock.

Feb 15 '07 #9
There is already a large chuck of code, I want to use that.
There is a sturcture(quite large) that is used at two different
location.
I dont want to waste memory(embedded device I dont have much) so i am
trying to use the same sturcture by using extern. If I use pointer I
have to
do a lot of mechanical changes(stuct to pointer to stuct) in one
module.

Regards
May I suggest a good old search and replace?

--
John
Feb 15 '07 #10
Richard Heathfield <rj*@see.sig.invalidwrites:
paresh said:
>Hi Friends,

Can we have a alias of a variable in C.

Like I define an int---
int example;

Now I want another variable that is the alias for the "example". I
meant both example and another variable let say "example2" have the
same memory but we are refrencing with it by two variables.

Yes, you could use #define, or you could simply point two pointers at
the same object.
>I need both to be global variables.

Why on earth would you need to do that?
>I am not talking about call by reference

No such thing in C.
This is misleading for a new person to C.

Arrays are, by default, "passed by reference" in any semi reasonable
interpretation of it phrase.
Feb 15 '07 #11
Richard wrote:
Richard Heathfield <rj*@see.sig.invalidwrites:
>paresh said:
>>I am not talking about call by reference

No such thing in C.

This is misleading for a new person to C.

Arrays are, by default, "passed by reference" in any semi reasonable
interpretation of it phrase.
Only in the sense that arrays aren't passed /at all/ in C.
The decay-to-pointer effect is not specific to argument
passing and I believe it does a disservice to C newbies to
connect it to the full-blow pass-by-reference found in
some other languages.

Of course, I'm not semi-reasonable, just detached-reasonable.

--
Chris "electric hedgehog" Dollin
"Who do you serve, and who do you trust?" /Crusade/

Feb 15 '07 #12

Richard wrote:
Richard Heathfield <rj*@see.sig.invalidwrites:
paresh said:
<snip>
I am not talking about call by reference
No such thing in C.

This is misleading for a new person to C.

Arrays are, by default, "passed by reference" in any semi reasonable
interpretation of it phrase.
True pass by reference doesn't exist in C. Pointers are used to
simulate it, with arrays being just a special case of this feature.

Feb 15 '07 #13
Richard said:
Richard Heathfield <rj*@see.sig.invalidwrites:
>paresh said:
>>I am not talking about call by reference

No such thing in C.

This is misleading for a new person to C.
No, it isn't. What is misleading is the pretence that there is such a
thing as pass-by-reference in C.
Arrays are, by default, "passed by reference"
No, arrays aren't passed *at all* in C.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 15 '07 #14
Richard Heathfield wrote:
Richard said:
>Richard Heathfield <rj*@see.sig.invalidwrites:
>>paresh said:

I am not talking about call by reference

No such thing in C.

This is misleading for a new person to C.

No, it isn't. What is misleading is the pretence that there is
such a thing as pass-by-reference in C.
>Arrays are, by default, "passed by reference"

No, arrays aren't passed *at all* in C.
Since Richard <nonamewants to intermix languages, maybe he will
describe to us how to implement 'pass by name' in C? Hint: read-up
on Algol.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
Feb 16 '07 #15

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

Similar topics

4
by: mexican_equivalent | last post by:
X-no-archive: yes Newbie C++ programmer reads the following statement from the C++ 'Deitel & Deitel' textbook: "Reference variables can be used as local aliases within a function. They must...
5
by: Dave N | last post by:
I posted this request earlier and was directed to some code that would not work. I am using win2000 Professional. I want to find out who is logged in to the computer and take that ID look it up...
42
by: baumann | last post by:
hi all, typedef int (*pfunc)(int , int); pfunc a_func; i know it's ok, but how can define a_func without typedef statement? thanks .
2
by: jbatty | last post by:
I am trying to display an image on my page by using "img src= hyperlink". the hyperlink is stored in a c# variable. but i seem to have the syntax mixed up. This passing the image directly works...
6
by: jcrouse | last post by:
I have a project with a startup (Sub Main) module and two forms. Based on the logic in the Sub Main it calls one of the two forms. The two forms are almost identical. They both make calls into the...
5
by: Jon Shemitz | last post by:
I'm playing with 2.0's extern alias declarations and the :: operator. If I have an extern alias My; and the My namespace contains a TypeName, I can refer to My::TypeName .... or to...
3
by: petermichaux | last post by:
Hi, Is there a way to make one property an alias for another? This would mean that if the value of the original is changed then so is the value of the alias. I tried the following example and it...
5
by: pauldepstein | last post by:
Take the code: int ival = 1024; int &refVal = ival; My text says "a reference is just another name for an object ... we can access refVal through ival ..." I understand this way of using...
9
by: lnatz | last post by:
Hi, I am writing a shell for a class and I have to write some builtins such as alias and cd. I am having some trouble with alias. I anyone could give me some ideas about how to do it I would...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.