In C there is no "case" equivalent for char arrays (strings) but it can be accomplished to some extent using a bit shifting macro and switch case
#define FIVE_CHARS(c1,c2,c3,c4,c5) (((((((((c5)<<7)|(c4))<<6)|(c3))<<6)|(c2))<<6)|(c1))
while (argc-->0){
switch ( FIVE_CHARS(argv[argc][0],argv[argc][1],argv[argc][2],argv[argc][3],argv[argc][4]) ){
case FIVE_CHARS('-','h','e','l','p') :
case FIVE_CHARS('-','-','h','e','l') :
case FIVE_CHARS('-','h','\0','\0','\0') :
case FIVE_CHARS('-','?','\0','\0','\0') :
usage();
break;
case FIVE_CHARS('-','a','r','g','1') :
setflag1();
break;
default:
assert("Argument not supported");
}
}
The compiler may compile this as a series of if's with a small number of comparisons or a jump table with a large number. This can provide significant improvement in both code size and speed since most of the bit shifts (those in the case statements) are done at compile time rather than run time, the remaining bit shift operation (the one in the switch) is relatively cheap and only needed once for a single comparison (essentially negating any need to put the most common paths first) ... for cases with matching five characters you can add an extra switch case for an uncommon character/characters or just use a strcmp() ... its still better to only need strcmp for a few cases though, rather than a huge nested tree of if strcmp() {} else if strcmp() {} else ...