open-mpi/hwloc

vsnprintf warnings

Closed this issue · 5 comments

When using super-picky compilation warning flags, hwloc gets warnings about vsnprintf:

{{{
/home/balaji/projects/mpich2/hydra/hydra/tools/bind/hwloc/hwloc/src/cpuset.c:
In function 'hwloc_snprintf':
/home/balaji/projects/mpich2/hydra/hydra/tools/bind/hwloc/hwloc/src/cpuset.c:37:
warning: implicit declaration of function 'vsnprintf'
/home/balaji/projects/mpich2/hydra/hydra/tools/bind/hwloc/hwloc/src/cpuset.c:37:
warning: nested extern declaration of 'vsnprintf'
}}}

Here's the flags that Pavan used to generate these warnings:

{{{
libtool: compile: gcc -DHAVE_CONFIG_H -I.
-I/home/balaji/projects/mpich2/hydra/hydra/tools/bind/hwloc/hwloc/src
-I../include/private -I../include/hwloc
-I/home/balaji/projects/mpich2/hydra/hydra/tools/bind/hwloc/hwloc/include
-I../include -std=c99 -Wall -Wmissing-prototypes -Wundef -Wpointer-arith
-Wcast-align -O2 -Wall -Wextra -Wno-missing-field-initializers
-Wstrict-prototypes -Wmissing-prototypes -DGCC_WALL
-Wno-unused-parameter -Wno-unused-label -Wshadow -Wmissing-declarations
-Wno-long-long -Wfloat-equal -Wdeclaration-after-statement -Wundef
-Wno-endif-labels -Wpointer-arith -Wbad-function-cast -Wcast-align
-Wwrite-strings -Wno-sign-compare -Waggregate-return
-Wold-style-definition -Wno-multichar -Wno-deprecated-declarations
-Wpacked -Wnested-externs -Winvalid-pch -Wno-pointer-sign
-Wvariadic-macros -std=c89 -Wno-format-zero-length -Wno-type-limits
-D_POSIX_C_SOURCE=199506L -MT cpuset.lo -MD -MP -MF .deps/cpuset.Tpo -c
/home/balaji/projects/mpich2/hydra/hydra/tools/bind/hwloc/hwloc/src/cpuset.c
-o cpuset.o >/dev/null 2>&1
}}}

Pavan suggested the following (on #16):

The vsnprintf warnings occur because snprintf and vsnprintf are present only in C99, not C89. There are a few solutions possible:

  1. Check in configure to (i) add a prototype for snprintf/vsnprintf where needed and (ii) add an alternative implementation for them for platforms that don't provide them.

  2. An alternative (simpler) solution is to include MPL ( https://svn.mcs.anl.gov/repos/mpi/mpich2/trunk/src/mpl) into hwloc and just use MPL_snprintf and friends everywhere.

  3. Check if snprintf/vsnprintf exist in configure and abort if they don't. Other libraries relying on hwloc can see this error and not build hwloc in those cases.

    Not sure if either approach is acceptable for you guys, so I'm leaving this ticket as closed. Please reopen if appropriate.

Imported from trac issue 18. Created by jsquyres on 2009-10-21T14:11:00, last modified: 2010-05-19T01:03:42

Trac comment by bgoglin on 2010-04-20 17:29:02:

Does any of this still apply/matter today?

Trac comment by jsquyres on 2010-04-21 07:57:17:

I don't think we should be targeting C89 -- that's just too old. C99 has some merit, and there's a few warnings left -- I'll dig a little...

Trac comment by jsquyres on 2010-04-21 08:27:35:

(In [1986]) Refs #18. Fix some compiler warnings:

  • Note the change of typeof to !typeof -- I got that from
    http://gcc.gnu.org/onlinedocs/gcc/Typeof.html.
  • I fixed a few places where local variables shadowed globals. On a
    RHEL 5.4 system, apparently <string.h> declares a global variable
    named "index" (!), and <math.h> declares a global named "y1".
    Who thought that was a good idea?

The compiler flags that I used to test this were (on RHEL 5.4):

{{{

With gcc 4.1.2

./configure CFLAGS="-std=c99 -Wall -Wmissing-prototypes -Wundef
-Wpointer-arith
-Wcast-align -O2 -Wall -Wextra -Wno-missing-field-initializers
-Wstrict-prototypes -Wmissing-prototypes -DGCC_WALL
-Wno-unused-parameter -Wno-unused-label -Wshadow
-Wmissing-declarations
-Wno-long-long -Wfloat-equal -Wdeclaration-after-statement -Wundef
-Wno-endif-labels -Wpointer-arith -Wbad-function-cast -Wcast-align
-Wwrite-strings -Wno-sign-compare -Waggregate-return
-Wold-style-definition -Wno-multichar -Wno-deprecated-declarations
-Wpacked -Wnested-externs -Winvalid-pch -Wno-pointer-sign
-Wvariadic-macros -Wno-format-zero-length
-D_POSIX_C_SOURCE=199506L"
2>&1 | tee config.out
}}}

and

{{{

With Intel compiler 10.0.0

./configure CC=icc CFLAGS="-std=c99 -Wall -Wmissing-prototypes
-Wpointer-arith
-O2 -Wall
-Wstrict-prototypes -Wmissing-prototypes -DGCC_WALL
-Wshadow -Wmissing-declarations
-Wpointer-arith
-Wwrite-strings
-Wno-multichar"
2>&1 | tee config.out
}}}

Trac comment by bgoglin on 2010-05-19 01:03:42:

1.0 is out, this should be ok now