This source code is switching on a string in C. How does it do that?

(Only you can answer the “macro trickery” part – unless you paste up more code. But there’s not much here for macros to work on – formally you are not allowed to redefine keywords; the behaviour on doing that is undefined.)

In order to achieve program readability, the witty developer is exploiting implementation defined behaviour. 'eax' is not a string, but a multi-character constant. Note very carefully the single quotation characters around eax. Most likely it is giving you an int in your case that’s unique to that combination of characters. (Quite often each character occupies 8 bits in a 32 bit int). And everyone knows you can switch on an int!

Finally, a standard reference:

The C99 standard says:

6.4.4.4p10: “The value of an integer character constant containing more than one character (e.g., ‘ab’), or containing a character or
escape sequence that does not map to a single-byte execution
character, is implementation-defined.”

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)