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: Label handling overhaul (C front end only)


"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


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