This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Label handling overhaul (C front end only)
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: "Zack Weinberg" <zack at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: 20 Jul 2003 01:43:24 +0200
- Subject: Re: Label handling overhaul (C front end only)
- Organization: Integrable Solutions
- References: <87smp2jdnf.fsf@egil.codesourcery.com>
"Zack Weinberg" <zack@codesourcery.com> writes:
[...]
| +The local label feature is useful for complex macros. If a macro
| +contains nested loops, a @code{goto} can be useful for breaking out of
| +them. However, an ordinary label whose scope is the whole function
| +cannot be used: if the macro can be expanded several times in one
| +function, the label will be multiply defined in that function. A
| +local label avoids this problem. For example:
I reiterate objections to this invention.
| +@example
| +#define SEARCH(value, array, target) \
| +do @{ \
| + __label__ found; \
| + typeof (target) _SEARCH_target = (target); \
| + typeof (*(array)) *_SEARCH_array = (array); \
| + int i, j; \
| + int value; \
| + for (i = 0; i < max; i++) \
| + for (j = 0; j < max; j++) \
| + if (_SEARCH_array[i][j] == _SEARCH_target) \
| + @{ (value) = i; goto found; @} \
| + (value) = -1; \
| + found:; \
| +@} while (0)
| +@end example
| +
| +This could also be written using a statement-expression:
If that could be written as statement-expression, then make that a
statment-expression. Please don't put a time-bomb.
-- Gaby