[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
declaring only the functions that are defined
From: |
Bruno Haible |
Subject: |
declaring only the functions that are defined |
Date: |
Tue, 2 Jan 2007 22:03:49 +0100 |
User-agent: |
KMail/1.9.1 |
Hi,
Some .h files declare functions which are defined in several modules.
This currently has the drawback that if your program is using, for example,
the gettime() function from the gettime module, and it also uses the
nanosleep() function without the nanosleep module, the program will compile
fine, even with -Wall, but give a link error.
With the new module presence macros, this can be made sharper.
I'm not sure all of you will welcome this technique: it causes the .h files
to depend on the module structure. (I.e. if you split a module into two
modules, you need to update the .h file.) It also merely turns a link error
into a compiler warning. On the other hand, the big win is that from looking
at the .h file, you see immediately which gnulib module you need. This is
useful when several (even dozens of) modules declare their functions in the
same .h file.
Opinions?
Simon, I have not included patches to gc.h and hmac.h, because I don't
understand these modules well enough.
2007-01-01 Bruno Haible <address@hidden>
* lib/timespec.h (nanosleep): Declare only if GNULIB_NANOSLEEP.
(gettime): Declare only if GNULIB_GETTIME.
(settime): Declare only if GNULIB_SETTIME.
* lib/c-strtod.h (c_strtod): Declare only if GNULIB_C_STRTOD.
(c_strtold): Declare only if GNULIB_C_STRTOLD.
* lib/stdio-safer.h (fopen_safer): Declare only if GNULIB_FOPEN_SAFER.
(tmpfile_safer): Declare only if GNULIB_TMPFILE_SAFER.
* lib/xstrtod.h (xstrtod): Declare only if GNULIB_XSTRTOD.
(xstrtold): Declare only if GNULIB_XSTRTOLD.
* lib/xstrtol.h (xstrtol, xstrtoul): Declare only if GNULIB_XSTRTOL.
(xstrtoimax): Declare only if GNULIB_XSTRTOIMAX.
(xstrtoumax): Declare only if GNULIB_XSTRTOUMAX.
*** lib/timespec.h.bak 2005-09-19 19:28:15.000000000 +0200
--- lib/timespec.h 2007-01-01 16:29:46.000000000 +0100
***************
*** 1,6 ****
/* timespec -- System time interface
! Copyright (C) 2000, 2002, 2004, 2005 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
--- 1,6 ----
/* timespec -- System time interface
! Copyright (C) 2000, 2002, 2004, 2005, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
***************
*** 50,62 ****
: a.tv_nsec - b.tv_nsec);
}
! # if ! HAVE_DECL_NANOSLEEP
/* Don't specify a prototype here. Some systems (e.g., OSF) declare
nanosleep with a conflicting one (const-less first parameter). */
int nanosleep ();
# endif
void gettime (struct timespec *);
int settime (struct timespec const *);
#endif
--- 50,67 ----
: a.tv_nsec - b.tv_nsec);
}
! # if GNULIB_NANOSLEEP && ! HAVE_DECL_NANOSLEEP
/* Don't specify a prototype here. Some systems (e.g., OSF) declare
nanosleep with a conflicting one (const-less first parameter). */
int nanosleep ();
# endif
+ # if GNULIB_GETTIME
void gettime (struct timespec *);
+ # endif
+
+ # if GNULIB_SETTIME
int settime (struct timespec const *);
+ # endif
#endif
*** lib/c-strtod.h.bak 2004-08-06 01:27:27.000000000 +0200
--- lib/c-strtod.h 2007-01-01 16:36:22.000000000 +0100
***************
*** 1,2 ****
! double c_strtod (char const *, char **);
! long double c_strtold (char const *, char **);
--- 1,6 ----
! #if GNULIB_C_STRTOD
! extern double c_strtod (char const *, char **);
! #endif
! #if GNULIB_C_STRTOLD
! extern long double c_strtold (char const *, char **);
! #endif
*** lib/stdio-safer.h.bak 2006-07-24 13:21:58.000000000 +0200
--- lib/stdio-safer.h 2007-01-01 17:02:29.000000000 +0100
***************
*** 1,6 ****
/* Invoke stdio functions, but avoid some glitches.
! Copyright (C) 2001, 2003, 2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
--- 1,6 ----
/* Invoke stdio functions, but avoid some glitches.
! Copyright (C) 2001, 2003, 2006-2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
***************
*** 20,24 ****
#include <stdio.h>
! FILE *fopen_safer (char const *, char const *);
! FILE *tmpfile_safer (void);
--- 20,29 ----
#include <stdio.h>
! #if GNULIB_FOPEN_SAFER
! extern FILE *fopen_safer (char const *, char const *);
! #endif
!
! #if GNULIB_TMPFILE_SAFER
! extern FILE *tmpfile_safer (void);
! #endif
*** lib/xstrtod.h.bak 2006-07-03 13:53:01.000000000 +0200
--- lib/xstrtod.h 2007-01-01 17:05:18.000000000 +0100
***************
*** 1,6 ****
/* Error-checking interface to strtod-like functions.
! Copyright (C) 1996, 1998, 2003, 2004, 2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
--- 1,6 ----
/* Error-checking interface to strtod-like functions.
! Copyright (C) 1996, 1998, 2003-2004, 2006-2007 Free Software Foundation,
Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
***************
*** 23,31 ****
--- 23,36 ----
# include <stdbool.h>
+ # if GNULIB_XSTRTOD
bool xstrtod (const char *str, const char **ptr, double *result,
double (*convert) (char const *, char **));
+ # endif
+
+ # if GNULIB_XSTRTOLD
bool xstrtold (const char *str, const char **ptr, long double *result,
long double (*convert) (char const *, char **));
+ # endif
#endif /* not XSTRTOD_H */
*** lib/xstrtol.h.bak 2006-10-20 00:23:38.000000000 +0200
--- lib/xstrtol.h 2007-01-01 17:06:40.000000000 +0100
***************
*** 1,6 ****
/* A more useful interface to strtol.
! Copyright (C) 1995, 1996, 1998, 1999, 2001, 2002, 2003, 2004, 2006
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
--- 1,6 ----
/* A more useful interface to strtol.
! Copyright (C) 1995, 1996, 1998, 1999, 2001, 2002, 2003, 2004, 2006, 2007
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
***************
*** 45,54 ****
--- 45,60 ----
# define _DECLARE_XSTRTOL(name, type) \
strtol_error name (const char *, char **, int, type *, const char *);
+ # if GNULIB_XSTRTOL
_DECLARE_XSTRTOL (xstrtol, long int)
_DECLARE_XSTRTOL (xstrtoul, unsigned long int)
+ # endif
+ # if GNULIB_XSTRTOIMAX
_DECLARE_XSTRTOL (xstrtoimax, intmax_t)
+ # endif
+ # if GNULIB_XSTRTOUMAX
_DECLARE_XSTRTOL (xstrtoumax, uintmax_t)
+ # endif
# define _STRTOL_ERROR(Exit_code, Str, Argument_type_string, Err) \
do \
- declaring only the functions that are defined,
Bruno Haible <=