Including <stddef.h>
sabbagh
sabbagh at acf5.NYU.EDU
Wed Sep 13 23:45:44 AEST 1989
In article <71 at motto.UUCP> dave at motto.UUCP (dave brown) writes:
>I am writing a header file to be used by other programmers. Within
>this file, one of the structures needs the type size_t. This means
>that in order to compile properly, <stddef.h>, which defines size_t,
>must be included as well. Since my header file will be used in
>programs I didn't write, I need to figure out how to make sure
><stddef.h> is included at the same time.
>
>Here are the ideas I have considered:
>
>1. Document the requirement
> [stuff deleted]
>2. Include <stddef.h> at the top of my header
As far as I have seen, 1. is the usual approach. If you want to
have <stddef.h> included in your own header file (as per 2.) the
best way to assure that it works is
1. Scan stddef.h for some symbol defined with an #define,
say, #define FOO
2. In your header, use the following:
#ifndef FOO
#include <stddef.h>
#endif
This will guarantee that your header file will always have the
stddef.h loaded, but it will cause problems for the user if
they try to #include <stddef.h> AFTER #including your header.
A third approach (if your are REALLY serious), is to copy those
parts of <stddef.h> into your own header file and #undef them when
your are done. This resolves all the above problems, but gives
up something in portability.
Isn't C great?
Hadil G. Sabbagh
E-mail: sabbagh at csd27.nyu.edu
Voice: (212) 998-3285
Snail: Courant Institute of Math. Sci.
251 Mercer St.
New York,NY 10012
186,282 miles per second -- it's not just a good idea, it's the law!
More information about the Comp.lang.c
mailing list