I'm writing an open source project that is designed to run on all kinds
of obscure architectures. My project relies on libcurl, which is in C89
and very portable. I don't want to limit the users' choice of compiler
unnecessarily. So, for example, I use malloc instead of variable length
arrays. Having said that, using long string literals seems pretty
harmless and I can't figure out a way to avoid usage of the other three
C99 features while retaining their functionality.
Richard
-----Original Message-----
From: David Brown <david@xxxxxxxxxxxxxxx>
To: gcc-help@xxxxxxxxxxx
Sent: Tue, Apr 5, 2011 8:47 pm
Subject: Re: How to use C89 with certain C99 features
On 05/04/2011 12:32, richardcavell@xxxxxxxx wrote:
Hi, everyone. I'm building a project in C. My idea is that I want it
to
be mostly C89, except that I will be using certain features of C99.
What
compiler flags do I need to tell GCC what I want?
What are you actually trying to achieve? The only reason I can think
of
for someone to write C89 standard is to be compatible with more limited
or older compilers. If that's the case, then you should write C89 -
not
C99. Many compilers that are basically C89 (or C90, or ANSI) will
accept a few C99 features, such as // comments. But they are very
unlikely to accept more complex C99 features, such as newer ways to
handle variadic parameters. Thus your code will only work with a
proper
C99 compiler, and thus might as well use --std=c99.
At present, if I compile with -std=c99, I get no errors or warnings at
all. If I compile with -std=c89, I get the following warnings:
(When I use macros with ... and __VA_ARGS__)
warning: anonymous variadic macros were introduced in C99
(When I use long string literals)
warning: string length '613' is greater than the length '509' ISO C90
compilers are required to support
(When I use vsnprintf)
warning: implicit declaration of function 'vsnprintf'
(When I initialize a struct with run-time data)
warning: initializer element is not computable at load time
Richard