Page 2 of 2

Re: Problem with test() and printf(const char *format, ...)

Posted: Sun Aug 24, 2008 4:08 pm
by Virtlink
Combuster wrote:Try it out :wink:

I would expect that you don't need those constructs by using those macros, since they are written for the compiler and hence should comply with the C standard and work as expected (independent of being inlined or not)
Indeed, using the following in my stdarg.h seems to work, and has the added advantage of the compiler warning when specifying a wrong argument type when calling va_arg. Simple, yet effective:

Code: Select all

#ifndef __STDARG_H
#define __STDARG_H

#define va_start(v,l) __builtin_va_start(v,l)
#define va_arg(v,l)   __builtin_va_arg(v,l)
#define va_end(v)     __builtin_va_end(v)
#define va_copy(d,s)  __builtin_va_copy(d,s)
typedef __builtin_va_list va_list;

#endif

Re: Problem with test() and printf(const char *format, ...)

Posted: Mon Aug 25, 2008 7:55 am
by quok
Combuster wrote:If you actually read the license it says something llike the following.

"This file is GPLed. However, you may use a compiled form of this file without GPLing the resulting binary"

In legalese:
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

(snip)

As a special exception, if you include this header file into source
files compiled by GCC, this header file does not by itself cause
the resulting executable to be covered by the GNU General Public
License. This exception does not however invalidate any other
reasons why the executable file might be covered by the GNU General
Public License.
Just to reiterate here, the GPL exception on the header files supplied by GCC is only valid if you are compiling your source code with GCC. I know that quite a few OS projects out there want to supply their own headers, but end up just copying ones out of GCC and in to their own include/ directory. Again, if you're compiling with GCC this isn't a big deal, but the moment you want to compile with pcc or the microsoft compiler, your project is now GPL'd.

I want to be able to compile my project (which is not GPL'd) with both GCC and pcc, so I supply my own headers even where GCC supplies ones that have the GPL exception. You can easily do the same thing that GCC does (which in the case of stdargs.h is #define va_* to __builtin_va_* for the most part), but not all compilers may implement the builtin function variants.

So for the record, just be careful when using GCC's supplied headers or you may run in to licensing problems down the road.

On a side note, one of the stated goals of (the new) pcc is to be compatible with gcc, so using the same builtin functions may or may not work there. My bet is just not to depend on them at all. :)