[LCP] Realloc and null pointers

Christopher Howard choward at indicium.us
Wed Feb 11 10:01:29 EST 2009


Let's say I declare a char pointer:

  char * label;

Can I simply allocate memory to it like so?:

  realloc(label, 100*sizeof(char));

Or do I need to malloc it first?

I read in the man pages that if "label" is null, realloc will behave just 
like malloc. But is the "label" pointer null by default, or do I have to 
assign it a NULL value to be sure?

I'm writing memory management functions to handle the memory in some of my 
structs, so I wanted to make things as simple as possible for myself.

-- 
Christopher Howard
http://indicium.us



More information about the linuxCprogramming mailing list