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;
} |} -
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;
} |}Good grief. Is that what them Borland guys meant by "Excellence Endures?" :rolleyes: Jeremy Falcon Imputek
-
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;
} |} -
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;
} |}Yuck! I thought I'd seen some nasty programming tricks but this one takes not only the biscuit but the whole tin. X| Anna :rose: www.annasplace.me.uk
"Be yourself - not what others think you should be"
- Marcia GraeschTrouble with resource IDs? Try the Resource ID Organiser Add-In for Visual C++
-
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;
} |}It might count as 'literate programming'. Would not look out of place in boost::preprocessor if they got rid of the comments. I'm jealous. Ryan.
They read good books, and quote, but never learn a language other than the scream of rocket-burn. Our straighter talk is drowned but ironclad; elections, money, empire, oil and Dad.
-
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;
} |}It's a State Machine Jim, but not as we know it. Phil
-
Convert it to templates and submit it to boost. :) Tim Smith I'm going to patent thought. I have yet to see any prior art.
-
It's a State Machine Jim, but not as we know it. Phil
:-D
They read good books, and quote, but never learn a language other than the scream of rocket-burn. Our straighter talk is drowned but ironclad; elections, money, empire, oil and Dad.
-
It's a State Machine Jim, but not as we know it. Phil
Hehe :laugh: Good one - I'm waiting for someone to nick that for their sig! :) Anna :rose: www.annasplace.me.uk
"Be yourself - not what others think you should be"
- Marcia GraeschTrouble with resource IDs? Try the Resource ID Organiser Add-In for Visual C++
-
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;
} |}What exactly are you taking issue with this code? The fact of the way they used Macros extensively, or because they used a switch statement to continue processing? Something like this could be useful for special situations, although there is probably a less convoluted way of accomplishing this.
Build a man a fire, and he will be warm for a day
Light a man on fire, and he will be warm for the rest of his life! -
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;
} |}This is sort of similar to Duff's Device - interleaving a switch with another program control construct. -- Ian Darling
-
Hehe :laugh: Good one - I'm waiting for someone to nick that for their sig! :) Anna :rose: www.annasplace.me.uk
"Be yourself - not what others think you should be"
- Marcia GraeschTrouble with resource IDs? Try the Resource ID Organiser Add-In for Visual C++
-
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;
} |}The C User's Journal used to run a yearly competition named "The obfuscated C code contest". I remember two entries that were amazing: the first piece of code was a perfectly formatted sine wave (seen from a distance); the other was a reversible C program :omg: - it would work (doing different things) if you inverted the lines (literally). From then on, I knew I would always be a NORMAL developer.
-
What exactly are you taking issue with this code? The fact of the way they used Macros extensively, or because they used a switch statement to continue processing? Something like this could be useful for special situations, although there is probably a less convoluted way of accomplishing this.
Build a man a fire, and he will be warm for a day
Light a man on fire, and he will be warm for the rest of his life!I like to analyze different programming styles to improve mine, doesn't matter if I agree with it or not. For long time I never seen nothing new, but using macros this way to continue processing is really something I've never seen before. As I said, I wouldn't support this programming, but certainly it's so original it’s mind opening, and could be useful in other situations.
-
The C User's Journal used to run a yearly competition named "The obfuscated C code contest". I remember two entries that were amazing: the first piece of code was a perfectly formatted sine wave (seen from a distance); the other was a reversible C program :omg: - it would work (doing different things) if you inverted the lines (literally). From then on, I knew I would always be a NORMAL developer.
-
I like to analyze different programming styles to improve mine, doesn't matter if I agree with it or not. For long time I never seen nothing new, but using macros this way to continue processing is really something I've never seen before. As I said, I wouldn't support this programming, but certainly it's so original it’s mind opening, and could be useful in other situations.
Ummm, I can understand, this might have been coded this way for a speed advantage. Have you checked the execution times vs your own versions? Regardz Colin J Davies
Sonork ID 100.9197:Colin
I'm guessing the concept of a 2 hour movie showing two guys eating a meal and talking struck them as 'foreign' Rob Manderson wrote:
-
I like to analyze different programming styles to improve mine, doesn't matter if I agree with it or not. For long time I never seen nothing new, but using macros this way to continue processing is really something I've never seen before. As I said, I wouldn't support this programming, but certainly it's so original it’s mind opening, and could be useful in other situations.
As I said, I wouldn't support this programming, but certainly it's so original it’s mind opening, and could be useful in other situations. A shotgun blast to the head is also mind opening, but it isn't something I would like to do. :) Tim Smith I'm going to patent thought. I have yet to see any prior art.
-
And what about a code which print's it self? This is, a C code which uses printf() to output exactly the original code.:-D I've once seen it, and some time later I wrote it again for fun.
Here's the programm which print's it self. This is the code I wrote. I saw it a long time ago, and I don't know who wrote the original code or what was it like. I think that one was simpler.
#include<stdio.h>
void main(void)
{
char* p1="#include<stdio.h>%cvoid main(void)%c{%c char* p1=%c%s%c;%c";
char* p2=" char* p2=%c%s%c;%c printf(p1,10,10,10,34,p1,34,10);%c printf(p2,34,p2,34,10,10,10);%c}";
printf(p1,10,10,10,34,p1,34,10);
printf(p2,34,p2,34,10,10,10);
} -
The C User's Journal used to run a yearly competition named "The obfuscated C code contest". I remember two entries that were amazing: the first piece of code was a perfectly formatted sine wave (seen from a distance); the other was a reversible C program :omg: - it would work (doing different things) if you inverted the lines (literally). From then on, I knew I would always be a NORMAL developer.
Some of the stuff they come up is pretty amazing. :wtf: The International Obfuscated C Code Contest[^]
Bruce Duncan, CP#9088, CPUA 0xA1EE, Sonork 100.10030
Blackadder: Baldrick, have you no idea what irony is?
Baldrick: Yeah, it's like goldy and bronzy only it's made of iron. -
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;
} |}HEhe. Ugly, but clever! -- Chatai. Yana ra Yakana ro futisha ta?