|
|
Log in / Subscribe / Register

C and C++ could have non_nullable pointers, easily

C and C++ could have non_nullable pointers, easily

Posted Aug 20, 2009 18:25 UTC (Thu) by hummassa (guest, #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


The LWN site is currently under high scraper load, so comment display has been suppressed for anonymous users. If you are a human, you may read the comments by clicking the button below:

Note: you can avoid this step in the future by logging into your LWN account.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds