G_STMT_START / G_STMT_END on Sun



Can anyone tell me what Sun compiler required that G_STMT_START/G_STMT_END be 
written as follows:

<inside gmacros.h>
#    if (defined (sun) || defined (__sun__))
#      define G_STMT_START      if (1)
#      define G_STMT_END        else (void)0
#    else

This is causing me headaches now and no longer seems to be any kind of 
requirement when compiling with even semi-recent Sun compilers:

$ cat a.c
#include <stdio.h>
int main(void)
{
    do { printf("foo\n"); } while(0);
}
$ /opt/SUNWspro61/bin/cc -o a a.c
$ /opt/SUNWspro8/bin/cc -o a a.c
$

Also, the macros are written in such a way that if you are using GCC in strict 
ANSI mode on a Sun machine, you will get the silly "if (1) else (void) 0" macros
 instead of the normal "do while(0)".

The end result of all of this is that the following code generates warnings on 
recent GCC versions on Solaris:

if (1)
    g_assert_not_reached();

$ /opt/gcc-3.4.3/bin/gcc <options here> -ansi test.c
warning: suggest explicit braces to avoid ambiguous `else'

If someone knows why those Sun checks existed in the first place, I'll post a 
patch to fix these macros to prevent this issue on Sun machines. The comment 
indicates they came from Perl code, but does not mention any version numbers. 
Next step, dig out the Perl src to see if they have an idea :)

Thanks,

Andrew Paprocki
Bloomberg LP






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]