Re: RFC: libkern version of inet_ntoa_r

From: Lev Serebryakov <lev_at_FreeBSD.org>
Date: Mon, 30 Jul 2012 11:12:09 +0400
Hello, Arnaud.
You wrote 30 июля 2012 г., 2:30:21:

>>  It looks very gcc-ish.
AL> could you back your point with a technical argument, please ? This
AL> sounds rather FUD'ish so far.
AL> The ({ ... }) is nothing more than a primary-expression enclosing a
AL> compound-statement;
  And how will it return value? It is completely illegal for compound
statement to return value. And to be a part of primary expression, too.

  Here is simple test:

=============================================================
1  #include <stdlib.h>
2  #include <stdio.h>
3
4  int fn(int x, int y) { return x + y; }
5
6  #define fn(x) ({ fn(x, 42); })
7
8  int main(int argc, char *argv[]) {
9          printf("%d\n", fn(10));
10         return 0;
11 }
=============================================================

  gcc compiles it and prints "52", but MSVC++ 10.0 cannot compile this
at all, and it is in its own right:

=============================================================
D:\home\lev\test>cl test.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

test.c
test.c(9) : error C2059: syntax error : '{'
test.c(9) : error C2059: syntax error : ')'
test.c(9) : error C2059: syntax error : ')'
test.c(10) : error C2059: syntax error : 'return'
test.c(11) : error C2059: syntax error : '}'
=============================================================

See http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html -- it is
clearly marked as "GNU C" construct, not ANSI/ISO C/C++ one.

And even more:

=============================================================
> gcc -Wall -ansi -pedantic -std=c99 test.c
test.c: In function 'main':
test.c:9: warning: ISO C forbids braced-groups within expressions
>
=============================================================

-- 
// Black Lion AKA Lev Serebryakov <lev_at_FreeBSD.org>
Received on Mon Jul 30 2012 - 05:12:13 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:29 UTC