NULL Pointer

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

NULL Pointer

288 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lmoreira on Wed Mar 30 02:27:34 MST 2011
Hi Guys,
I have defined a type of variable using typedef called MultiBuffer, then I created an array of MultiBuffers.
I have a function that returns a pointer to one of the positions of the array, i.e. a MultiBuffer, when there are no more Multibuffer available for use I would like to return a NULL pointer to signal that there are no more pointers available.
When I used this on Pelles C it worked fine but in LPCXpresso it says it is not defined. I get that, but is there a way of doing the same thing.
I know I can get around this by returning a flag instead that can be just an int but that will make the function a bit messier.
Thanks
Best Regards
                    Luis
0 Kudos
3 Replies

273 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Mar 30 07:15:31 MST 2011
You're kidding me :):)

'0' is where this pointer points to. You asked for a Null pointer = pointer, which is pointing to '0'.

See

http://en.wikipedia.org/wiki/Pointer_(computing)#Null_pointer
0 Kudos

273 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lmoreira on Wed Mar 30 06:59:02 MST 2011
Hi Zero,
That works very well, but I don't understand why... The void* is defining a void pointer but what is the "0" for?
I had a look around for info about this but can not find anything that really resembles the way you are using it.
Thanks
Best Regards
                    Luis
0 Kudos

273 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Mar 30 02:59:27 MST 2011
[LEFT][COLOR=blue]/* NULL pointer */[/COLOR]
[COLOR=blue]#ifndef NULL[/COLOR]
[COLOR=blue]#define NULL ((void*) 0)[/COLOR][/LEFT]
[COLOR=blue]#endif[/COLOR]
0 Kudos