Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Casting a memory address

Reply
Thread Tools

Casting a memory address

 
 
cman
Guest
Posts: n/a
 
      03-03-2007
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

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      03-03-2007
cman wrote:
> 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().

--
Ian Collins.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Up casting and down casting Sosuke C++ 2 12-20-2009 03:24 PM
Problem with depracated casting method (down casting) Wally Barnes C++ 3 11-20-2008 05:33 AM
Memory allignment/type casting question MisterE C Programming 6 10-09-2008 12:11 AM
HPUX Invalid Address Alignment when assigning double, casting to same type works? Jay Hamilton C++ 1 08-11-2006 03:32 PM
Another question about inheritance (up-casting and down-casting) kevin Java 11 01-08-2005 07:11 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57