Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 29 Jul 2012 18:30:21 -0400
From:      Arnaud Lacombe <lacombar@gmail.com>
To:        lev@freebsd.org
Cc:        "Bjoern A. Zeeb" <bzeeb-lists@lists.zabbadoz.net>, Luigi Rizzo <rizzo@iet.unipi.it>, current@freebsd.org, David Chisnall <theraven@freebsd.org>
Subject:   Re: RFC: libkern version of inet_ntoa_r
Message-ID:  <CACqU3MUZJH2FcWbYL0UBNwhztQRtY%2Bsk-ZGxywgg43pFe4ZyRw@mail.gmail.com>
In-Reply-To: <1119098728.20120730003000@serebryakov.spb.ru>
References:  <20120725155211.GA33971@onelab2.iet.unipi.it> <alpine.BSF.2.00.1207282213171.4474@ai.fobar.qr> <20120729095833.GB80946@onelab2.iet.unipi.it> <CBCC6E24-8D03-422E-B571-1B62FB7667E6@FreeBSD.org> <20120729191958.GB85015@onelab2.iet.unipi.it> <CACqU3MVNCOdde7atRVT7xaYH1qHjm=4uS0Eih8EgG3=DDaOGCw@mail.gmail.com> <20120729204721.GA87481@onelab2.iet.unipi.it> <1119098728.20120730003000@serebryakov.spb.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi,

On Sun, Jul 29, 2012 at 4:30 PM, Lev Serebryakov <lev@freebsd.org> wrote:
> Hello, Luigi.
> You wrote 30 =D0=B8=D1=8E=D0=BB=D1=8F 2012 =D0=B3., 0:47:21:
>
>>> #define fn(x)   ({ fn(x, 42); })
> LR> nice trick, one always learns something on these lists...
> LR> now i wonder how it works with MSVC (windows being one of the
> LR> other platforms where i need to build the ipfw+dummynet code...)
>  It looks very gcc-ish.
>
could you back your point with a technical argument, please ? This
sounds rather FUD'ish so far.

The ({ ... }) is nothing more than a primary-expression enclosing a
compound-statement; this part is not specifically necessary. As for
the expansion, I would assume the following part of iso9899:1999
applies:

<<
6.10.3 Macro replacement

10
A preprocessing directive of the form

# define identifier lparen identifier-listopt ) replacement-list new-line
# define identifier lparen ... ) replacement-list new-line
# define identifier lparen identifier-list , ... ) replacement-list new-lin=
e

defines a function-like macro with arguments, similar syntactically to
a function call. [...] Each subsequent instance of the function-like
macro name followed by a ( as the next preprocessing token introduces
the sequence of preprocessing tokens that is replaced by the
replacement list in the definition (an invocation of the macro). The
replaced sequence of preprocessing tokens is terminated by the
matching ) preprocessing token, [...]
>>

Note that the standard say "Each subsequent", no "All", so

fn(1, 2);
#define fn(a) fn(a, 2)
fn(1);

would produces:

fn(1, 2);

fn(1, 2);

I do not see any gcc'ism here.

Now, I might be wrong, and would enjoy being proven so.

Thanks,
 - Arnaud



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CACqU3MUZJH2FcWbYL0UBNwhztQRtY%2Bsk-ZGxywgg43pFe4ZyRw>