The most original code I've ever seen
-
After years programming in C and C++, I thought I've seen it all. But I've found a code so original and complicated as I've never seen before, that I think it worth a look, even if noone would use something like this. Please, don't do things like this. This is a function which can execute in parts. This is, you can return from the function, and when you call it again, it starts processing from where it returned. (This does NOT work in Visual C, I think Borland was used). Anyway, here's the code:
ORIGINAL CODE |MACRO EXPANSION, FOR CLARITY
----------------------------+------------------------------------------------
#define xxStart \ |
static int iLine = 0; \ |
switch (iLine){case 0: |
|
#define xxEnd } |
|
#define xxReturn(x) \ |
{ iLine=__LINE__; \ |
return 1; \ |
case __LINE__:}; |
|
int f (void) |int f (void)
{ |{
xxStart | static int iLine = 0; switch (iLine){case 0:
|
...Processing... | ...Processing...
|
if (condition) | if (condition)
xxReturn(1); | {iLine=__LINE__; return 1; case __LINE__:};
|
...Processing... | ...Processing...
|
// More data required | // More data required
xxReturn(3); | { iLine=__LINE__; return 3; case __LINE__:};
|
...Processing... | ...Processing...
|
xxEnd | }
|
return 0; | return 0;
} |}Omigawd, that's wretched :omg:. I've seen that kind of crap before. When I started my current job, I took over a project from a guy who did stuff like the following:
#define void int
and
#define CASEND4 case 5: \
DoSomething(); \
break; \
default: \
DoSomethingElse(); \
break;\
}My first official act, after looking this sh*t crap over, was to carefully archive it and then lose the backup.
Software Zen:
delete this;
-
Omigawd, that's wretched :omg:. I've seen that kind of crap before. When I started my current job, I took over a project from a guy who did stuff like the following:
#define void int
and
#define CASEND4 case 5: \
DoSomething(); \
break; \
default: \
DoSomethingElse(); \
break;\
}My first official act, after looking this sh*t crap over, was to carefully archive it and then lose the backup.
Software Zen:
delete this;
I used to work, doing C, at a place where they had a few Pascal programmers. They had the following defined:
#define begin { #define end }
I kid you not, we were expected to use them! :omg:
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed) NEW: Awasu 1.0[^]: A free RSS reader with support for Code Project.
-
I used to work, doing C, at a place where they had a few Pascal programmers. They had the following defined:
#define begin { #define end }
I kid you not, we were expected to use them! :omg:
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed) NEW: Awasu 1.0[^]: A free RSS reader with support for Code Project.
Yuck. Unfortunately, in my case, this guy was just plain stupid. He had been a programmer for 25+ years, and nobody ever had the cojones to tell him he wasn't any good at it. Or maybe they did, and he simply didn't get the message. The one good thing was, he was finally laid off, and ended up working for one of our competitors ( :laugh: tee hee :laugh: ).
Software Zen:
delete this;