This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

Re: compiler tweak offered


[replying to rth@redhat.com]

>> 	for "outer" (elt=root; elt; elt=elt->link)
>> 		 if (...) continue "outer";
> I don't know about the other maintainers, but personally I don't feel
> this extension adds enough expressiveness to warrent the maintanence
> hassle.  Really, this is just as easily written as

> 	for (elt=root; elt; elt=elt->link)
> 		if (...) goto continue_outer;
> 	  continue_outer:;

Yes, except for three things: (1) it requires someone attempting to
understand the control flow to check the whole rest of the function to
see if that label is used anywhere else; (2) it can't be done twice in
the same function (you have to pick different label names, whereas loop
names can be reused freely); and (3) when you as a maintainer see the
goto, you have to check that it really is doing what it looks as though
it's doing.

>> Unfortunately it does cause a reinterpretation of certain very
>> unusual legal C code, namely, any do-loop whose body is a
>> non-brace-bracketed statement beginning with a string literal...
> In addition, this is a major strike against your proposal.

This is surely fixable.  For example, if a C/ObjC statement cannot
begin with < (which I think is the case but I'm not quite sure), then
names could be specified as <"string"> rather than just "string" and
the ambiguity would vanish.  (Maybe even make them identifiers rather
than string literals then.)

Alternatively, do-loops could simply have to do without names.

[replying to zack@codesourcery.com]

> I do like the idea on an aesthetic level, but I don't see a hugely
> compelling case for it.

For the main gcc tree, neither do I.  It's an offer, and I would not be
surprised if it were declined.  (Marginally disappointed, perhaps, but
not surprised.)

For myself, I just got fed up with "goto break2_a" in one loop and
"goto break2_b" in the next.

> It would be better to use real labels:

>   outer: for (elt=root; elt; elt=elt->link)
> 		 if (...) continue outer;

Better in that respect.  It would lose in two of the respects I
mentioned above, though: (1) it means you can't have a given loop name
more than once in a given function and (2) it would open up that target
to gotos as well as continues and breaks.

Oh, and it would lose in a third respect as well: I doubt I would have
been able to implement it.  You people may well be able to drop it in
in an afternoon; I don't think I can.  I did what I could rather than
regretting being unable to do what I couldn't. :-)

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


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