This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC's statement expression extension
- To: Mike Stump <mrs at windriver dot com>
- Subject: Re: GCC's statement expression extension
- From: Jamie Lokier <egcs at tantalophile dot demon dot co dot uk>
- Date: Fri, 4 Aug 2000 13:35:25 +0200
- Cc: gcc at gcc dot gnu dot org, mark at codesourcery dot com, per at bothner dot com
- References: <200008032132.OAA10481@kankakee.wrs.com>
[Mark: the toupper example is not correct]
Mike Stump wrote:
> > printf("%s", toupper((a+b).c_str()[0]));
>
> Nope, not a problem. You need one that takes and returns the same
> char *...
You are right, but the macro doesn't have to return the same char * for
there to be a problem.
If the macro had the form ({ char * s = (arg); do_something_with(s); })
then it would break because arg, being (a+b).c_str(), would be destroyed
after s was assigned and before evaluating do_something_with(s).
Here is an example using Glibc's <bits/string2.h> implementation of
strcmp. (Work through the mass of __builtin_constant_p to the
__strcmp_cg call).
printf ("%s", (!strcmp ("yes", (a+b).c_str())) ? "equal" : "not equal");
enjoy,
-- Jamie