xlc and <sys/dir.h> brain damage

Chuck Karish karish at pangea.Stanford.EDU
Thu May 16 10:30:51 AEST 1991


In article <2811 at sapwdf.UUCP> Bill Wohler <wohler at sap-ag.de> writes:
>  the following example compiles under cc, but not under xlc.  why not?

When the C compiler is invoked as 'xlc', it enforces
the namespace limitations specified by POSIX.1.  No symbols other
than those defined by Standard C are visible in the headers
unless a feature test macro is #defined or the symbol is in the
namespace reserved for the implementation.  'cc' defines '_AIX',
which causes '_POSIX_SOURCE' and '_XOPEN_SOURCE' to be set
as well.

>  is this brain damage in the way dir.h or standards.h is set up?
>  the meat of dir.h is only included if _POSIX_SOURCE is defined,
>  which isn't defined when _ANSI_C_SOURCE is as in the case with
>  xlc.

That's what the standards require.  Declarations of 'DIR' and
'opendir()' would infringe on the namespace that's reserved for
the programmer.

>  does anyone really use xlc?

Yes.  You do, too; 'cc' actually is an alias for 'xlc'.

Calling the compiler as 'xlc' doesn't just change the feature test
macros.  It changes the semantics of the compiler in many subtle ways
to match the C Standard.

>[wohler at is0002:507]% cat foo.c
>#include <dirent.h>
>foo()
>{
>        DIR *dirname = opendir("/tmp");
>}
>[wohler at is0002:508]% cc -c foo.c
>[wohler at is0002:509]% xlc -c foo.c
>        5 |         DIR *dirname = opendir("/tmp");
>            ........a....b.........................
>a - 1506-045: (S) Undeclared variable.
>b - 1506-045: (S) Undeclared variable.

>Bill Wohler <wohler at sap-ag.de> <sapwdf!wohler>
--

	Chuck Karish		karish at mindcraft.com
	(415) 323-9000		karish at forel.stanford.edu



More information about the Comp.unix.aix mailing list