Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. The most original code I've ever seen

The most original code I've ever seen

Scheduled Pinned Locked Moved The Lounge
c++delphi
23 Posts 16 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gabriel 2
    wrote on last edited by
    #1

    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;
    } |}

    J T A R P 10 Replies Last reply
    0
    • G Gabriel 2

      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;
      } |}

      J Offline
      J Offline
      Jeremy Falcon
      wrote on last edited by
      #2

      Good grief. Is that what them Borland guys meant by "Excellence Endures?" :rolleyes: Jeremy Falcon Imputek

      1 Reply Last reply
      0
      • G Gabriel 2

        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;
        } |}

        T Offline
        T Offline
        Tim Smith
        wrote on last edited by
        #3

        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.

        P 1 Reply Last reply
        0
        • G Gabriel 2

          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;
          } |}

          A Offline
          A Offline
          Anna Jayne Metcalfe
          wrote on last edited by
          #4

          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 Graesch

          Trouble with resource IDs? Try the Resource ID Organiser Add-In for Visual C++

          1 Reply Last reply
          0
          • G Gabriel 2

            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;
            } |}

            R Offline
            R Offline
            Ryan_Roberts
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • G Gabriel 2

              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;
              } |}

              P Offline
              P Offline
              Phil Speller
              wrote on last edited by
              #6

              It's a State Machine Jim, but not as we know it. Phil

              R A 2 Replies Last reply
              0
              • T Tim Smith

                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.

                P Offline
                P Offline
                peterchen
                wrote on last edited by
                #7

                Do I see some irony here, sir? :rooleyes:


                So many people long for eternity that don't know what to do on a rainy sunday afternoon.
                [sighist] | [Agile Programming] [doxygen]
                If you look for evil in me you will find it whether it's there or not.

                1 Reply Last reply
                0
                • P Phil Speller

                  It's a State Machine Jim, but not as we know it. Phil

                  R Offline
                  R Offline
                  Ryan_Roberts
                  wrote on last edited by
                  #8

                  :-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.

                  1 Reply Last reply
                  0
                  • P Phil Speller

                    It's a State Machine Jim, but not as we know it. Phil

                    A Offline
                    A Offline
                    Anna Jayne Metcalfe
                    wrote on last edited by
                    #9

                    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 Graesch

                    Trouble with resource IDs? Try the Resource ID Organiser Add-In for Visual C++

                    L 1 Reply Last reply
                    0
                    • G Gabriel 2

                      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;
                      } |}

                      P Offline
                      P Offline
                      Paul M Watt
                      wrote on last edited by
                      #10

                      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!

                      G 1 Reply Last reply
                      0
                      • G Gabriel 2

                        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;
                        } |}

                        I Offline
                        I Offline
                        Ian Darling
                        wrote on last edited by
                        #11

                        This is sort of similar to Duff's Device - interleaving a switch with another program control construct. -- Ian Darling

                        1 Reply Last reply
                        0
                        • A Anna Jayne Metcalfe

                          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 Graesch

                          Trouble with resource IDs? Try the Resource ID Organiser Add-In for Visual C++

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #12

                          ;P Good one - I'm waiting for someone to nick that for their sig!

                          1 Reply Last reply
                          0
                          • G Gabriel 2

                            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;
                            } |}

                            J Offline
                            J Offline
                            Joao Paulo Figueira
                            wrote on last edited by
                            #13

                            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.

                            G B 2 Replies Last reply
                            0
                            • P Paul M Watt

                              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!

                              G Offline
                              G Offline
                              Gabriel 2
                              wrote on last edited by
                              #14

                              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.

                              C T 2 Replies Last reply
                              0
                              • J Joao Paulo Figueira

                                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.

                                G Offline
                                G Offline
                                Gabriel 2
                                wrote on last edited by
                                #15

                                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.

                                G 1 Reply Last reply
                                0
                                • G Gabriel 2

                                  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.

                                  C Offline
                                  C Offline
                                  ColinDavies
                                  wrote on last edited by
                                  #16

                                  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:

                                  1 Reply Last reply
                                  0
                                  • G Gabriel 2

                                    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.

                                    T Offline
                                    T Offline
                                    Tim Smith
                                    wrote on last edited by
                                    #17

                                    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.

                                    1 Reply Last reply
                                    0
                                    • G Gabriel 2

                                      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.

                                      G Offline
                                      G Offline
                                      Gabriel 2
                                      wrote on last edited by
                                      #18

                                      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);
                                      }

                                      1 Reply Last reply
                                      0
                                      • J Joao Paulo Figueira

                                        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.

                                        B Offline
                                        B Offline
                                        Bruce Duncan
                                        wrote on last edited by
                                        #19

                                        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.

                                        1 Reply Last reply
                                        0
                                        • G Gabriel 2

                                          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;
                                          } |}

                                          J Offline
                                          J Offline
                                          Jorgen Sigvardsson
                                          wrote on last edited by
                                          #20

                                          HEhe. Ugly, but clever! -- Chatai. Yana ra Yakana ro futisha ta?

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups