Re: G_STMT_START / G_STMT_END on Sun



On Fri, 11 Nov 2005, ANDREW PAPROCKI, BLOOMBERG/ 731 LEXIN wrote:

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 :)

the first mentioning of that is in a 1997 email from owen, i have
appended it. so if you're looking for a particular perl version, it's
one from before that date ;)


Thanks,

Andrew Paprocki
Bloomberg LP



_______________________________________________
gtk-devel-list mailing list
gtk-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-devel-list


---
ciaoTJ



From owt1 cornell edu Thu Dec  4 00:27:11 1997
Date: Wed, 03 Dec 1997 09:25:56 -0500
From: Owen Taylor <owt1 cornell edu>
Reply-To: gtk-list redhat com
To: gtk-list redhat com
Subject: [gtk-list] Re: g_assert() and consorts into {}?
Resent-Date: 3 Dec 1997 16:30:02 -0000
Resent-From: gtk-list redhat com
Resent-cc: recipient list not shown: ;


i'd like to see all the macros around g_assert () (return_if_fail...),
to be enclosed by {}.

[ ... ]


any objections?

A good idea, but just {} is a bad idea - it can lead to warnings
(errors?) on some systems.

Here's how Perl does it:

/*
 * STMT_START { statements; } STMT_END;
 * can be used as a single statement, as in
 * if (x) STMT_START { ... } STMT_END; else ...
 *
 * Trying to select a version that gives no warnings...
 */
#if !(defined(STMT_START) && defined(STMT_END))
# if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__cplusplus)
#   define STMT_START	(void)(	/* gcc supports ``({ STATEMENTS; })'' */
#   define STMT_END	)
# else
   /* Now which other defined()s do we need here ??? */
#  if (VOIDFLAGS) && (defined(sun) || defined(__sun__))
#   define STMT_START	if (1)
#   define STMT_END	else (void)0
#  else
#   define STMT_START	do
#   define STMT_END	while (0)
#  endif
# endif
#endif

We can probably just adopt this pretty much wholesale.
VOIDFLAGS is a #define which is true if 'void' is defined.
Since we don't care about pre-ANSI systems, we probably
can omit that. I'm not sure why SunOS (?) systems warn
about do { } while (0), but it doesn't cost much to
leave that in.

Regards,
                                        Owen

--
To unsubscribe: mail -s unsubscribe gtk-list-request redhat com < /dev/null




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