C and C++ could have non_nullable pointers, easily
Posted Aug 20, 2009 18:25 UTC (Thu) by
hummassa (subscriber, #307)
In reply to:
Null pointers, one month later by hppnq
Parent article:
Null pointers, one month later
Put some pragma to deal with legacy code, etc...
int *nonnull a = NULL; // syntax error
int *b = NULL; // Ok
int f(int *nonnull c) { return *c; } // ok
int g(int *d) { return *d; } // syntax error
int h(int *e) {
if( e ) {
// here, "e" is of type "int *nonull" b/c of the check
return *e;
} else {
return 0;
}
} // ok
f(b); // syntax error
h(b); // ok
if( b ) f(b); // ok
(
Log in to post comments)