Re: C question for you old guys ;-)
Re: C question for you old guys ;-)
- Subject: Re: C question for you old guys ;-)
- From: Pete Yandell <email@hidden>
- Date: Mon, 23 Jun 2003 11:58:44 +1000
Martin,
What you have to understand about pointers is that their type makes a
difference to pointer arithmetic. For example, if I do:
long* x = 0;
x++;
x will now have the value of 4, because the compiler assumes that you
want to point x at the next long, not the next byte. Similarly:
x + 1024;
is actually 4096.
So the question is: is the freeSpacePointer type _really_ an unsigned
char*?
Pete Yandell
http://pete.yandell.com/
On Monday, June 23, 2003, at 08:24 AM, Martin Hdcker wrote:
Hi there,
to get back on topic of programming, could anybody of you tell me why
this bit of code produces two different results?
freeSpacePointer adress = 0x00040000; // Really a ((unsigned char *)
0x00040000)
long tryToGet = 1024; // 0x400
// return freeSpacePointer + tryToGet; /* Doesn't work... Why? */
// returns 0x42000
// versus
return (freeSpacePointer)((long)adress + tryToGet);
// returns 0x40400 -- what I wanted to get
I didn't find this by my first attempts of unit-testing, so I'd like
to understand it. :) Any advice?
Thanks,
Martin
--
dont.wanna.tell
[ot]coder - hehe
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.