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


>>>>> "Alexandre" == Alexandre Oliva <aoliva@redhat.com> writes:

    Alexandre> Maybe the way to go is to require statement expressions
    Alexandre> to contain explicit `return' statements, at least in
    Alexandre> C++.  This would at least make it easier to support
    Alexandre> them in C++.  Is `return' currently usable within
    Alexandre> statement expressions?

Yes, but that means `return from this function', not `return from the
statement expression'.  (Which is why Per's analogy to inlining isn't
quite perfect, even in C.  If you're compiling Scheme to C, you want
to generate a `goto' in the statement expression (to a label later in
the statement expression) where in Scheme you had a `return'.)

So, making `return' in a statement expression mean `exit the statement
expression' would be the worst kind of change: it would change the
meaning of valid programs.

I think that Per's analogy of Scheme->C with OO Functional->C++ is not
that good.  The Scheme->C translation is much more tractable than the
C++ translation.  Many functional OO languages do not map well onto
C++.  (For example, if they allow method replacement, vtables are not
what you want.)  In C, inline functions get (well, the compiler should
do better) you 95% of the value of statement expressions.  The typeof
extension gets you a little extra power.  In C++, you can use inline
functions and templates to get all of that power.

I think the only compellilng arguments for keeping statement
expressions in C++ are:

  o They appear in headers that we need to compile in C++.
  
  o Some users may rely on them.

Those are important arguments, but I don't think there's a compelling
reason in the language itself.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

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