Is there a way to assign an address to a non-pointer global variable???
Is there a way to assign an address to a non-pointer global variable???
Well sure. An address is just a number:
What exactly are you trying to do?????!!!!!OMFGBBQCode:unsigned long foo = 0x12345678; void *ptr = 0x12345678;
If you understand what you're doing, you're not learning anything.
unsigned long foo = 0x12345678;
Just sets foo.
I am trying to set the address of foo to 0x12345678
Is there a way to do that without making foo a pointer?
Be careful because you might truncate the address depending on what the code is compiled on.Code:someVar = (someVar's type) &someOtherVar
edit; I should have more carefully read your reply, you can't change the address of a variable because it's either a relative address on the stack that the compiler works with itself or some offset in a data section in your built application. Maybe with some wierd pragma or attribute you could set the address but I can't think of a reason you would want to. What are you trying to do in a broader sense (say, the entire function or application)?
Last edited by valis; 08-11-2006 at 12:26 PM.
I don't think there's a way to change the address of foo by even making it a pointer. You shouldn't care where variables are placed in memory unless you're doing something suspicious.
If you understand what you're doing, you're not learning anything.
The code is compiled on a Unix Machine.
When trying the code you suggested I get the following error.
"Conversion to non-scalar type requested"
Why would you want to do this? You can not make up an address to assign a variable to. You can make a pointer and then make it point to an address. If you could pick the address off a variable, what is to make sure you are not overwriting other variables, or doing malicious stuff.
Help populate a c/c++ help irc channel
server: irc://irc.efnet.net
channel: #c
I have an array of structures. I need to allocate fixed memory space, so that I can manipulate this array of structures, which needs to be in this fixed mem space.
I think that making a pointer to a structure type, and then setting that pointer to point to this space is probably the best way to go.
Code:struct foo *structptr = (struct foo *)fixed_memory_ptr;
If you understand what you're doing, you're not learning anything.
Thank you!!!