This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC's statement expression extension
>>>>> "Per" == Per Bothner <per@bothner.com> writes:
Per> Mark Mitchell <mark@codesourcery.com> writes:
>> statement expressions ... don't have documented semantics in
>> C++ (for example, when does a temporary created in the
>> statement expression go away?),
Per> Intuitively, it seems to me there is only one rational
Per> answer: when you exit the (block of) the statmenet
Per> expression.
That seems like the obvious right answer. It just doesn't work very
well for:
X x;
X f();
x = ({ f(); });
Oops. The return value of f() got destroyed before we got a chance to
copy it. (There are more complex examples with similar problems,
including binding things to references, which cause lifetime
extensions in C++.)
I *am* a pretty experienced Scheme programmer. (And ML, and other
functional languages.) The problem is that the basic programming
model in C++ is different, and programmers think about things
differently. Scheme is tremendously useful as a foundational
programming language analysis tool; every course I've taken or taught
on programming language theory features Scheme, and many use it as a
foundation onto which other programming languages are mapped. But,
it's not always enough to simply say "if this were Scheme, what would
it mean?".
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com