This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: GCC's statement expression extension


[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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]