Prohibit use of break/continue in a statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a macro that expands to a for-loop. It is used as follows:

    MACRO(...) {
        // User code
    }

The for-loop is used to open a new scope with a new variable; thus,
`MACRO(...) { ... }` would be a proper C statement. The loop itself is
executed only once.

The problem is that if a user uses `break` or `continue` like this:

    while (i < 10) {
        MACRO(...) {
           break;
            // User code...
       }
    }

Then that `break` will apply to the for-loop generated by `MACRO`, not
to the outer while-loop. The same holds for `continue`. This is
unexpected behaviour, and I would like to prohibit the use of the
`break`/`continue` statements in a user statement placed after
`MACRO`. Ideally, this should somehow trigger a compilation
error/warning.

It should be clarified that `MACRO` is not of a loop itself: it is not
a for-each macro or something like this; using that for-loop is just
an implementation detail. I would be also happy with getting rid of
that for-loop but I have no idea how. If I just generate a variable
like this:

    #define MACRO(...) int x; /* Some other stuff */

Then `MACRO(...) { ... }` will no longer be a single C statement.
Moreover, two occurrences of `MACRO` calls in a single scope will
result in a compilation error, which is also quite unfortunate.

Is it possible to trigger a compilation warning/error for
`break`/`continue` with GCC?



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux