handling uninitialized pointed (How to check ?? )

R

Richard Heathfield

Niklas Norrthon said:
So where is the bug in this code?

#include <stdio.h>

/* pointer not initialised to NULL following... */
const char* msg = "This is a message.";

Right - it's clearly not a bug. He'd have been wiser to say something like
"anywhere where you define (not declare, define) a pointer without
initialising it to a known value (which might be NULL), consider it a bug".
 
S

slebetman

Niklas said:
So where is the bug in this code?

#include <stdio.h>

/* pointer not initialised to NULL following... */
const char* msg = "This is a message.";

int main(void)
{
printf("%s\n", msg);
return 0;
}

Ah but that pointer is pointing to something. I was commenting on
pointers not pointing to anything, which IMHO should always be set to
NULL. Sanjay thought that manually setting a pointer to NULL is too
much work hence my rant about not setting it to NULL should be
considered a bug.

I went into rant mode because I was not the first person who mentioned
NULL to him but the guy insisted on not setting it to NULL. Later on
(after my rant) he said what if users of his library doesn't set the
pointer to NULL? My point is that should be considered a bug. Actually,
for Sanjay's addDynamicMemory code initialising the pointer to static
memory is indeed a bug as his function will attempt to realloc it. So
in the context of the OP's intention, not initialising a pointer to
NULL is indeed a bug.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top