Till Crueger wrote:
I know you shouldn't do this, but I just thought of a really nasty way to
Yes, you should do it! Be bold and push C to its limits;
figure out why things are the way they are. This is IMO
what could make the difference between being/becomming a
regular programmer and an expert.
obfuscate c code. I am however not sure if this is correct c at all. What
I did was this:
file obfuscate.c:
#include <stdio.h>
int main(int argc, char* argv[]){
#include "obfuscate.h"
}
file obfuscate.h:
printf("hello world\n");
I also tried some variations on this scheme, and my compiler accepted all
of them. But does it have to, or is this not valid c?
See the C preprocessor as a simple text-processor with a
limited set of #-operations. The #include simply and only
replaces itself by the literal contents of the named
file. Many compilers allow you to see the code that is
actually (i.e., after all text #-operations have been
replaced by code) using a command line option (some compiler
have -E). During preprocessing there is no notion of C
grammar/syntax. (So, you could (mis)use the C preprocessor
for other purposes.)
<OT>
An obfuscated program that does nice in this context is:
#include </dev/tty> /* /dev/tty is the 'command tool' device */
Which at least works on UNIX machines. When running the
compiler on this program, the compiler connects its input
to the command tool from which you just invoked the compiler.
So, you can start typing the actual program. When done, you
can close the input using ^D, and of the compiler goes finishing
it's job.
</OT>
Good luck!
Kees