Standard alternative for gnu custom case ranges

I have a question for a quick workaround to take advantage of non-standard gnu argument ranges . For example, non-standard:

case 1 ... 5:

It can be replaced by:

case 1:
case 2:
case 3:
case 4:
case 5:

Perhaps some macro solution might be ok. From my memory, macro loops cannot loop into a large number of iterations. For this reason, if the range is "large", say, in thousands?

+4
source share
2 answers

, , boost. , , , , , 255 "". , - ( ). , .

, , if - else if - else. , () , , , ( ).

, switch - case , default if-else if-else .

script, case , , case , , , ... . ( ) , case-range .

+2

if/else. , , .

, "" , , Duff (, ), .

, , "". . while C , .

python awk script. , - -. , , , .

, . ( script), STATE_10 STATE_20, , ? - GNU .

case , , , :

, () :

switch(state)
{
case STATE_1:
    xxx; break;
case STATE_2 ... STATE_10:
    yyy; break;
}

. . if/else , , . :

#if !defined(__GNUC__)

#define STATE_RANGE_2_10 101

if(state >= 2 && state <= 10)
    state2 = STATE_RANGE_2_10
else if(...)
    state2 = STATE_RANGE_x_y
else
    state2 = state;

#else /* GNU */

#define STATE_RANGE_2_10 STATE_2 ... STATE_10
state2 = state;

#endif

switch(state2)
{
case STATE_1:
    xxx; break;
case STATE_RANGE_2_10:
    yyy; break;
}

GNUC C, , GNUC - . . state2 , . , .

+2

Source: https://habr.com/ru/post/1617567/


All Articles