cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: yangtse: curl/lib sendf.c,1.125,1.126 sendf.h,1.33,1.34

From: Jamie Lokier <jamie_at_shareable.org>
Date: Sat, 31 Mar 2007 15:31:48 +0100

Dan Fandrich wrote:
> On Tue, Mar 27, 2007 at 10:04:43AM -0700, James Dennett wrote:
> > Or something like the following?
> > #define infof (void) sizeof Curl_infof
>
> That's pretty freaky--does it really compile? And is it ANSI C?

It compiles with GCC 2.7.2, GCC 2.7.2 with -traditional, GCC 4.1, and
G++ 4.1. So it's probably fine syntax. That's consistent with C
operator precedence: "sizeof" has higher precedence than binary
operators, and lower or right-to-left equal precdence with unary
operators and function application.

But remember to make sure Curl_infof doesn't return "void", as you
can't take the size of void. (On GCC you can, so it won't be noticed).

It's weird enough that it might not work with some other compilers,
even if it's valid ANSI C, especially older compilers. So it's
probably worth trying it on a few before using it as the fallback
macro for old unknown compilers :-)

Or, perhaps an Autoconf test to check the syntax is accepted, and use
the "(void)" cast version instead, or an empty function body, if not
(just in case)?

I would not be surprised if this "sizeof" macro still puts unwanted
strings into the binary with some compilers, but it seems less likely
to do so than the other macros.

-- Jamie
Received on 2007-03-31