nonnull attribute

Patrick Pelissier Patrick.Pelissier at loria.fr
Tue Jul 20 11:39:09 CEST 2004


 Do you plan to add nonnull attribute of GCC in GMP?
 Not very usefull, but may be interesting.

Extract of GCC: 
"
`nonnull (ARG-INDEX, ...)'
     The `nonnull' attribute specifies that some function parameters
     should be non-null pointers.  For instance, the declaration:

          extern void *
          my_memcpy (void *dest, const void *src, size_t len)
                __attribute__((nonnull (1, 2)));

     causes the compiler to check that, in calls to `my_memcpy',
     arguments DEST and SRC are non-null.  If the compiler determines
     that a null pointer is passed in an argument slot marked as
     non-null, and the `-Wnonnull' option is enabled, a warning is
     issued.  The compiler may also choose to make optimizations based
     on the knowledge that certain function arguments will not be null.

     If no argument index list is given to the `nonnull' attribute, all
     pointer arguments are marked as non-null.  To illustrate, the
     following declaration is equivalent to the previous example:

          extern void *
          my_memcpy (void *dest, const void *src, size_t len)
                __attribute__((nonnull));
"

 Sincerely,
  Patrick Pelissier


More information about the gmp-devel mailing list