C
Christopher Benson-Manica
[comp.lang.c] Eric Sosman said:Christopher Benson-Manica wrote On 11/06/07 11:07,:void baz() {
void *qux = NULL;
/* Oops, forgot to initialize pointer */
foo( qux );
}
Maybe I'm just being dense today (or this year, or
this life), but I still don't get it. Drop the silly
initialization, and a good compiler will *already* warn
about the probable error -- and not just for pointers,
either.
You're right - sorry. <ot>The Java IDE I use (IntelliJ IDEA)
suggests initializing variables in this fashion, a habit that has
merits and drawbacks, but in any case doesn't really fit the C
paradigm. said:As far as I can see, the only "use case" is for
variations on
char *p = malloc(strlen(s) + 1);
/* no NULL check here */
strcpy (p, s);
This is a class of error I can't recall having made (I
make others instead), so I'm not especially attracted by
machinery that helps me solve a problem I don't have.
malloc() might not be a good example, since its behavior is
standardized and well-known to all with access to a man page. OTOH
user functions (possibly written by other developers) don't enjoy that
luxury, and might profitably be "annotated" (to borrow a term) to
return "NULLable" or "not NULL".
A way to make assertions about values might be a
useful thing, but I think it should be in a more general
framework than just NULL-or-not.
I agree (as I alluded to in my last paragraph). It seems to me that
implementations would have to retain the right to ignore such
assertion suggestions (much as they retain the right to ignore the
register keyword), and in any case I don't believe that such additions
to C would provide the benefits that they do in other langusages.