Another useless C99 tidbit
From page 18 of the C99 standard:
All occurrences in a source file of the following sequences of three characters (called trigraph sequences) are replaced with the corresponding single character.
??= # ??( [ ??/ \ ??) ] ??' ^ ??< { ??! | ??> } ??- ~No other trigraph sequences exist. Each ? that does not begin one of the trigraphs listed above is not changed.
Ok, so take the following C program:
??=include <stdio.h> int main(int argc, char *argv??(??)) ??< printf("hello world\n"); ??>
And compile it with the -trigraphs switch to gcc:
dirac src $ gcc -trigraphs -o trigraphs trigraphs.c dirac src $ ./trigraphs hello world
Combined with this you could seriously obfuscate your C code.
Hidden Gems in C99 (1)
After some late night reading of the C99 spec, I've found quite a few hidden gems. I'm going to start posting some of these. Since it's late, I'll just post a teaser.
On page 64 of the C99 standard it says:
In all aspects of the language, the six tokens
<: :> <% %> %: %:%:behave,respectively,the same as the six tokens
[ ] { } # ##except for their spelling.
Really? Then let's try this program:
%:include <stdio .h> int main(int argc, char *argv<::>) <% printf("hello world\n"); %>
Compile it an run it:
dirac src $ gcc main.c dirac src $ ./a.out hello world
Whaddaya know... I know, I know... useless. Wait for the next post then.
