Menu

#67 gcc attributes: stronger compile time error checking

aolserver_v41
closed-accepted
None
5
2005-08-23
2004-08-16
Stephen
No

The attached patch introduces a new header file:
nsattributes.h. It contains defines for gcc attributes
(see gcc docs) which allow you to more accurately
describe your intentions when specifying functions,
types and variables.

For example, you can specify that a function takes
printf like arguments, in which case gcc will check
their types and number for you. Or, you can specify
that certain parameters should never be null.

I've annotated some of the source in a series of small,
seperate patches. If you look at the considerably
cleaner output of a compile with the patches applied,
you'll see a couple of obvious bugs which should be fixed.

Bigger gains in safety could likely be had by judicious
use of the _nsnonnull and _nswarnunused attributes.
The _nsdeprecated attribute would help module writers alot.

In the future, some of the splint (see: splint.org)
markup could be added. I'm sure there are bugs in the
code that this would turn up...

Discussion

  • Stephen

    Stephen - 2004-08-16

    gcc attributes support

     
  • Stephen

    Stephen - 2004-08-16

    check format strings

     
  • Stephen

    Stephen - 2004-08-16

    malloc optimization

     
  • Stephen

    Stephen - 2004-08-16
     
  • Stephen

    Stephen - 2004-08-16
     
  • Jim Davidson

    Jim Davidson - 2005-08-23
    • assigned_to: nobody --> jgdavidson
    • status: open --> closed-accepted
     
  • Dossy Shiobara

    Dossy Shiobara - 2005-08-23

    Logged In: YES
    user_id=21885

    FWIW, using gcc-specific features in our code means not
    being able to build with, for example, Sun Forte compiler on
    Solaris, which for 64-bit builds may be desirable. Or
    possibly using the Intel C compiler on x86/EM64T.

     
  • Dossy Shiobara

    Dossy Shiobara - 2005-08-23

    Logged In: YES
    user_id=21885

    (It looks like the patches are all "safe" in that they
    become no-ops on non-gcc builds. Cool.)

     
  • Jamie Rasmussen

    Jamie Rasmussen - 2005-08-24

    Logged In: YES
    user_id=522678

    Adding nsattributes.h caused two problems with the windows
    build (non-gcc).

    1) I think the top of nsattributes.h is missing something like:

    #else
    # define __GNUC_PREREQ(maj, min) 0

    2) Microsoft Visual C++ doesn't support variadic macros.
    This annoying situation is finally addressed in Visual
    Studio 2005 but that's still in beta. In the meantime, the
    win32 build can't handle the definition (or any uses, though
    I don't see any yet) of this line:

    # define _nsnonnull(...)

     
  • Jim Davidson

    Jim Davidson - 2005-08-24

    Logged In: YES
    user_id=20624

    Fixed compile with non-gcc compiler including on windows.

     

Log in to post a comment.