Casting a memory address

C

cman

What is the effective behaviour if you cast a memory address? I have
come across code where memory address 0 is cast to a 'struct foo'
type. What does this amount to? Does address 0 now point to address 0
of the 'struct foo'?

cman
 
I

Ian Collins

cman said:
What is the effective behaviour if you cast a memory address?

The same as if you cast anything, you coerce the compiler into assigning
a value to a pointer.
I have
come across code where memory address 0 is cast to a 'struct foo'
type. What does this amount to? Does address 0 now point to address 0
of the 'struct foo'?
Not a lot, you just end up with a foo* with a value of 0, or what ever
value you assigned to it. The example you posted was simply a dodgy way
to implement offsetof().
 

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
473,780
Messages
2,569,611
Members
45,268
Latest member
AshliMacin

Latest Threads

Top