> 1) would one use xlc to compile code using, for example, <sys/dir.h>?
Yes, if one's program is designed to be compiled under Standard C.
Quote:> if so, 2) what magic would one have to perform to get DIR and opendir()
> and so on defined?
-D_POSIX_SOURCE makes DIR and opendir() visible. Depending on what's
included in "and so on", -D_XOPEN_SOURCE or -D_ALL_SOURCE may be
Quote:>i'm not too hip on this standards stuff and
> doing something like defining _POSIX_SOURCE in my makefile gives me
> the heebie-jeebies.
It shouldn't. It's there to make it easier for you to write
portable programs without getting bitten by an extension provided
by your system.
Quote:> by the way, is it appropriate for mere mortal programmers to define
> _POSIX_SOURCE, __STDC__, _ANSI_C_SOURCE and so on in ones makefile
> (obviously if they are not set by built-in macros or <standard.h>)?
__STDC__, no. The others, yes.
Quote:> perhaps there is a document that describes these standards and
These macros are called "feature test macros". They were invented by
the POSIX.1 committee to allow standards to be layered without
stepping on one anothers' name spaces.
The idea is that if you compile a C program on a POSIX-conforming
system that provides Standard C language support and do not have
_POSIX_SOURCE #defined, only those symbols specified in the C
standard and those in the namespaces reserved for the implementation
and for the user are visible in the standard headers. Each feature
test macro you #define makes more symbols visible.
In your case, you want to make some POSIX symbols visible, so you
should #define _POSIX_SOURCE. If you also need some symbols that are
#defined in the XPG but not by POSIX.1, #define _XOPEN_SOURCE as
The POSIX.1 standard describes feature test macros. There are
separate documents that describe the POSIX.1 and C standards and the
XPG. UniForum publishes several extended brochures that summarize
UNIX-related software standards in very general terms.
You may also want to take a look at "The POSIX.1 Standard: A
Programmer's Guide" by Fred Zlotnick, hot off the press from Benjamin
Cummings, ISBN 0-8053-9605-5. O'Reilly has just published a book
with similar scope by Don Lewine.
If you want to use Standard C but never want to have to worry about
feature test macros, make another entry in /etc/xlc.cfg that doesn't
#define _ANSI_SOURCE. To see why this will make all AIX symbols
visible, take a look at /usr/include/standards.h.