Nullable/Notnull : syntax proposal

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.
 
C

Christopher Benson-Manica

[comp.lang.c] Mark McIntyre said:
OTOH the OP's suggestion seems to be
intended to generate a fatal error message?

That does seem to be the case. Other considerations aside, I believe
that the nature of C and its current compilers make it unlikely that
any such "sudden death" compilation checks will be implmented by any
vendor, any of which may already provide extensions that addrress these
issues (albeit in a nonportable manner).
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top