Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - NULL Pointers | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
beneficii

Lakitu
Level: 36

Posts: 375/567
EXP: 299656
For next: 8454

Since: 06-27-04
From: Cordova, TN, USA

Since last post: 14 hours
Last activity: 6 hours
Posted on 07-30-05 10:09 PM Link | Quote
I wonder, If you malloc a pointer or create any variable, will it ever get assigned the address of 0 (NULL)? In other words, will a pointer ever get a NULL address from the system?


(edited by beneficii on 07-30-05 01:09 PM)
Dish

Spiny
Level: 38

Posts: 489/596
EXP: 355646
For next: 14801

Since: 03-15-04
From: Disch

Since last post: 18 days
Last activity: 18 days
Posted on 07-30-05 10:22 PM Link | Quote
On most systems -- no, you will never get a return of 0 (except on error).

However, that's why you're supposed to use NULL and not 0 (since were a system to have 0 a valid address, you would only have to redefine NULL to make it something else). I never stuck to that though, and I treat NULL as 0 always.


Even if 0 were a valid address... the lowest you could get would probably be like 8 or 16 or something -- since memory allocation functions allocate a bit more than you request and prefix it with information (like allocated size, and boundary checks)
beneficii

Lakitu
Level: 36

Posts: 376/567
EXP: 299656
For next: 8454

Since: 06-27-04
From: Cordova, TN, USA

Since last post: 14 hours
Last activity: 6 hours
Posted on 07-30-05 10:27 PM Link | Quote
Originally posted by Disch
On most systems -- no, you will never get a return of 0 (except on error).

However, that's why you're supposed to use NULL and not 0 (since were a system to have 0 a valid address, you would only have to redefine NULL to make it something else). I never stuck to that though, and I treat NULL as 0 always.


Even if 0 were a valid address... the lowest you could get would probably be like 8 or 16 or something -- since memory allocation functions allocate a bit more than you request and prefix it with information (like allocated size, and boundary checks)


Whoo, that just took a load off my back! Thanks Disch!

My guess is that 0 is used by the system somehow (like for BIOS or something).
Ramsus

Octoballoon
Level: 19

Posts: 153/162
EXP: 34651
For next: 1126

Since: 01-24-05
From: United States

Since last post: 39 days
Last activity: 71 days
Posted on 07-30-05 11:24 PM Link | Quote
When used as a pointer value in C, the constant 0 is always considered NULL according to the language's standard, not the actual memory address 0. In fact, the system can use any value it wants to represent a NULL pointer and the constant 0 will always be equivalent to it in any pointer context (e.g. assignment to a pointer variable).

If you're doing system-specific C code and store pointer addresses in something not a pointer, like an integer, you'll need to typecast 0 as (void *) in order to store an actual NULL value.
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 6167/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 07-31-05 03:04 AM Link | Quote
No OS I know of would assign memory that low. That area's generally reserved for the OS or BIOS. OSes usually reserve the lowest memory addresses for themselves.
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Programming - NULL Pointers | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.007 seconds.