Fix compile issues for C89 compilers.

Glynn Clements glynn at gclements.plus.com
Mon Apr 18 10:38:46 EDT 2011


Jeff Sparkes wrote:

> >> GCC has a -C89 switch or something like that that either enforces or
> >> warns about C89 compatibility.
> >
> > -std=c89 (for C, this is equivalent to -ansi). If you use that switch,
> > you typically need to explicitly define feature macros (-D_POSIX_SOURCE,
> > -D_XOPEN_SOURCE, etc), otherwise the standard C headers (<stdio.h> etc)
> > will omit declarations which aren't part of the C standard.
> 
> I compiled with -ansi successfully without changes.  (After I fixed the
> error I had introduced.)  I didn't look at any warnings though.
> I just tried with -std=c89 and it failed at line 1389 in lisp.h, which
> is DECLARE_INLINE_HEADER.  It must turn off gcc extensions, wchi aren't
> standard anyway.  :-)
> 
> So we could use -ansi with gcc.  Or would that be on linux?  I'm not
> sure which condition would trigger it.  I've added it to my personal
> configuration script.

You also need -pedantic to generate all of the diagnostics required by
the standard. Using -ansi/-std alone ensures that standards-conformant
programs won't fail to compile due to extensions (e.g. due to symbol
conflicts caused by the declaration of additional symbols in standard
headers).

Using -ansi/-std without adding the feature macros can result in code
compiling and linking successfully but failing at run-time due to
missing prototypes (and thus missing implicit type conversions).

I suspect that -ansi/-std= may not be viable on Windows; the Win32
headers tend to take MSVC extensions for granted.

-- 
Glynn Clements <glynn at gclements.plus.com>



More information about the XEmacs-Beta mailing list