This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to use C89 with certain C99 features


* On Tue, Apr 5, 2011 at 1:09 PM,  <richardcavell@mail.com> wrote:
> I'm writing an open source project that is designed to run on
> all kinds of obscure architectures.

obscure architectures may lack vsnprintf() or implement it
differently that expected.

We had similar issues in some (proprietary) packages and had to
include own vsnprintf implementations or using alternative
implementations (for example, instead of nicely formatted
strings, strcat constructions or not having this feature).

> 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.

so on obscure platforms, alternatives for the price of losing
part of the functionality have to be used I think.

> (When I use macros with ... and __VA_ARGS__)
> warning: anonymous variadic macros were introduced in C99

you may try to use functions instead, no vaargs macros (but
instead double-brace-macros that define to nothing or so).

> (When I use long string literals)
> warning: string length '613' is greater than the length '509' ISO
> C90 compilers are required to support
(I only get this warning when -Woverlength-strings,
my newest gcc (SUSE Linux) 4.5.1 20101208 [gcc-4_5-branch revision 167585])

Ohh, I didn't knew that.
Any ideas how to workaround this?
malloc + strcat/memcpy maybe?

> (When I use vsnprintf)
> warning: implicit declaration of function 'vsnprintf'

Bigger problem usually would be that you won't be able to link
without it.

> (When I initialize a struct with run-time data)
> warning: initializer element is not computable at load time

Could you please tell me how to get this warning?
It would help me sometimes.

this is when having e.g.:

  function func(long seconds)
  {
  	struct timeval t = { seconds, 0 };
  }

right? then instead you have to use

  function func(long seconds)
  {
  	struct timeval t = { 0 };
  	t.tv_sec = seconds;
  }

or so. Otherwise, compilation will abort or leave t undefined.

oki,

Steffen


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]