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. Other Discussions
  3. The Weird and The Wonderful
  4. Interesting technique used in some Legacy code!

Interesting technique used in some Legacy code!

Scheduled Pinned Locked Moved The Weird and The Wonderful
26 Posts 12 Posters 3 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.
  • D DeathByChocolate

    This was at the top of the code:

    #define 300 1
    #define 100 0

    I'm amazed that the compiler even accepted it! :rolleyes:

    "State acheived after eating too many chocolate-covered coconut bars - bountiful" Chris C-B

    N Offline
    N Offline
    Nagy Vilmos
    wrote on last edited by
    #2

    Wow! You broke maths!

    D 1 Reply Last reply
    0
    • D DeathByChocolate

      This was at the top of the code:

      #define 300 1
      #define 100 0

      I'm amazed that the compiler even accepted it! :rolleyes:

      "State acheived after eating too many chocolate-covered coconut bars - bountiful" Chris C-B

      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu Peter
      wrote on last edited by
      #3

      No problem with the compiler, but that code should give a one-way ticket to the developer...

      I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

      D 1 Reply Last reply
      0
      • N Nagy Vilmos

        Wow! You broke maths!

        D Offline
        D Offline
        DeathByChocolate
        wrote on last edited by
        #4

        It wasn't me! :rolleyes: :laugh: :laugh: I couldn't believe it compiled, but it must have. I guess there was a bug in the compiler that let it through because now it doesn't. :rolleyes:

        "State acheived after eating too many chocolate-covered coconut bars - bountiful" Chris C-B

        1 Reply Last reply
        0
        • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

          No problem with the compiler, but that code should give a one-way ticket to the developer...

          I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

          D Offline
          D Offline
          DeathByChocolate
          wrote on last edited by
          #5

          Kornfeld Eliyahu Peter wrote:

          that code should give a one-way ticket to the developer...

          He's gone! :-D ... but that means someone else has to sort it out! :( :rolleyes:

          "State acheived after eating too many chocolate-covered coconut bars - bountiful" Chris C-B

          Kornfeld Eliyahu PeterK 1 Reply Last reply
          0
          • D DeathByChocolate

            Kornfeld Eliyahu Peter wrote:

            that code should give a one-way ticket to the developer...

            He's gone! :-D ... but that means someone else has to sort it out! :( :rolleyes:

            "State acheived after eating too many chocolate-covered coconut bars - bountiful" Chris C-B

            Kornfeld Eliyahu PeterK Offline
            Kornfeld Eliyahu PeterK Offline
            Kornfeld Eliyahu Peter
            wrote on last edited by
            #6

            It shouldn't take more than one block of chocolate to you :laugh:

            I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

            "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

            D 1 Reply Last reply
            0
            • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

              It shouldn't take more than one block of chocolate to you :laugh:

              I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

              D Offline
              D Offline
              DeathByChocolate
              wrote on last edited by
              #7

              If only consumption of chocolate would fix that code! :rolleyes:

              "State acheived after eating too many chocolate-covered coconut bars - bountiful" Chris C-B

              1 Reply Last reply
              0
              • D DeathByChocolate

                This was at the top of the code:

                #define 300 1
                #define 100 0

                I'm amazed that the compiler even accepted it! :rolleyes:

                "State acheived after eating too many chocolate-covered coconut bars - bountiful" Chris C-B

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #8

                Well, the good news is it wasn't hidden away in a header file... :omg: If it's any consolation, A FORTRAN compiler I used to work with years, and years ago would accept a constant value as a function parameter, and let you change it at run time. I can't remember FORTRAN syntax any more but it would be similar to:

                void MyMethod (ref int i)
                {
                i = 666;
                }
                ...
                Console.WriteLine(42);
                MyMethod(42);
                Console.WriteLine(42);

                Would happily print: 42 666

                Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                M Kornfeld Eliyahu PeterK M 3 Replies Last reply
                0
                • OriginalGriffO OriginalGriff

                  Well, the good news is it wasn't hidden away in a header file... :omg: If it's any consolation, A FORTRAN compiler I used to work with years, and years ago would accept a constant value as a function parameter, and let you change it at run time. I can't remember FORTRAN syntax any more but it would be similar to:

                  void MyMethod (ref int i)
                  {
                  i = 666;
                  }
                  ...
                  Console.WriteLine(42);
                  MyMethod(42);
                  Console.WriteLine(42);

                  Would happily print: 42 666

                  Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                  M Offline
                  M Offline
                  Marco Bertschi
                  wrote on last edited by
                  #9

                  You surely meant to write

                  void MyMethod (const int i)
                  {
                  i = 666;
                  }

                  The console is a black place

                  OriginalGriffO 1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    Well, the good news is it wasn't hidden away in a header file... :omg: If it's any consolation, A FORTRAN compiler I used to work with years, and years ago would accept a constant value as a function parameter, and let you change it at run time. I can't remember FORTRAN syntax any more but it would be similar to:

                    void MyMethod (ref int i)
                    {
                    i = 666;
                    }
                    ...
                    Console.WriteLine(42);
                    MyMethod(42);
                    Console.WriteLine(42);

                    Would happily print: 42 666

                    Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                    Kornfeld Eliyahu PeterK Offline
                    Kornfeld Eliyahu PeterK Offline
                    Kornfeld Eliyahu Peter
                    wrote on last edited by
                    #10

                    OriginalGriff wrote:

                    I can't remember FORTRAN syntax any more

                    Getting old?!

                    I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

                    "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

                    OriginalGriffO 1 Reply Last reply
                    0
                    • M Marco Bertschi

                      You surely meant to write

                      void MyMethod (const int i)
                      {
                      i = 666;
                      }

                      The console is a black place

                      OriginalGriffO Offline
                      OriginalGriffO Offline
                      OriginalGriff
                      wrote on last edited by
                      #11

                      No, that implies the wrong thing. The compiler stored all it's constant values in memory locations, so it could happily pass a reference (or more accurately in those days a machine code pointer) to a constant value and it would act like a variable. Total PITA to debug when you met it for the first time: and a hanging offence to leave in production code...

                      Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                      F C 2 Replies Last reply
                      0
                      • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

                        OriginalGriff wrote:

                        I can't remember FORTRAN syntax any more

                        Getting old?!

                        I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

                        OriginalGriffO Offline
                        OriginalGriffO Offline
                        OriginalGriff
                        wrote on last edited by
                        #12

                        I haven't used it for years - and archive retrieval is a lot slower than online storage! :laugh:

                        Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                        B 1 Reply Last reply
                        0
                        • OriginalGriffO OriginalGriff

                          I haven't used it for years - and archive retrieval is a lot slower than online storage! :laugh:

                          Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                          B Offline
                          B Offline
                          Bernhard Hiller
                          wrote on last edited by
                          #13

                          OriginalGriff wrote:

                          archive retrieval

                          Magnetic tape at 300 baud? Does the tape reader still work with current Windows?

                          OriginalGriffO 1 Reply Last reply
                          0
                          • D DeathByChocolate

                            This was at the top of the code:

                            #define 300 1
                            #define 100 0

                            I'm amazed that the compiler even accepted it! :rolleyes:

                            "State acheived after eating too many chocolate-covered coconut bars - bountiful" Chris C-B

                            B Offline
                            B Offline
                            Bernhard Hiller
                            wrote on last edited by
                            #14

                            As a side-effect, wouldn't it change 30000 to 0 via 30000 -> 100 -> 0?

                            1 Reply Last reply
                            0
                            • D DeathByChocolate

                              This was at the top of the code:

                              #define 300 1
                              #define 100 0

                              I'm amazed that the compiler even accepted it! :rolleyes:

                              "State acheived after eating too many chocolate-covered coconut bars - bountiful" Chris C-B

                              P Offline
                              P Offline
                              phil o
                              wrote on last edited by
                              #15

                              What happens then when you try to divide a number by 100? Just curious ^^

                              There are two kinds of people in the world: those who separate humankind in two distinct categories, and those who don't. "I have two hobbies: breasts." DSK

                              D 1 Reply Last reply
                              0
                              • B Bernhard Hiller

                                OriginalGriff wrote:

                                archive retrieval

                                Magnetic tape at 300 baud? Does the tape reader still work with current Windows?

                                OriginalGriffO Offline
                                OriginalGriffO Offline
                                OriginalGriff
                                wrote on last edited by
                                #16

                                I wish! This is the long term storage between my ears we are talking about here... :laugh: I just wish I could find a way to re-index it occasionally ;)

                                Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                                1 Reply Last reply
                                0
                                • P phil o

                                  What happens then when you try to divide a number by 100? Just curious ^^

                                  There are two kinds of people in the world: those who separate humankind in two distinct categories, and those who don't. "I have two hobbies: breasts." DSK

                                  D Offline
                                  D Offline
                                  DeathByChocolate
                                  wrote on last edited by
                                  #17

                                  I guess, if you did try to do that, you would get a 'divide by 0 error'. Fortunately its only a small project and neither 100 or 300 were ever used as absolute values. It loaded a int with either 300 or 100 (ie 0 or 1) then later it checked to see if that int was equal to 300 or 100 (ie 0 or 1), so it did work but not a technique I would recommend! :rolleyes: :-D

                                  "State acheived after eating too many chocolate-covered coconut bars - bountiful" Chris C-B

                                  P 1 Reply Last reply
                                  0
                                  • D DeathByChocolate

                                    I guess, if you did try to do that, you would get a 'divide by 0 error'. Fortunately its only a small project and neither 100 or 300 were ever used as absolute values. It loaded a int with either 300 or 100 (ie 0 or 1) then later it checked to see if that int was equal to 300 or 100 (ie 0 or 1), so it did work but not a technique I would recommend! :rolleyes: :-D

                                    "State acheived after eating too many chocolate-covered coconut bars - bountiful" Chris C-B

                                    P Offline
                                    P Offline
                                    phil o
                                    wrote on last edited by
                                    #18

                                    Me neither :)

                                    There are two kinds of people in the world: those who separate humankind in two distinct categories, and those who don't. "I have two hobbies: breasts." DSK

                                    1 Reply Last reply
                                    0
                                    • OriginalGriffO OriginalGriff

                                      No, that implies the wrong thing. The compiler stored all it's constant values in memory locations, so it could happily pass a reference (or more accurately in those days a machine code pointer) to a constant value and it would act like a variable. Total PITA to debug when you met it for the first time: and a hanging offence to leave in production code...

                                      Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                                      F Offline
                                      F Offline
                                      Freak30
                                      wrote on last edited by
                                      #19

                                      Changing the value of a literal for subsequent uses of the same literal is pure evil. Who could have ever thought, it was a good idea to implement constants that way? :omg: Was it possibly done to keep the image size of the executable small?

                                      The good thing about pessimism is, that you are always either right or pleasently surprised.

                                      OriginalGriffO 1 Reply Last reply
                                      0
                                      • F Freak30

                                        Changing the value of a literal for subsequent uses of the same literal is pure evil. Who could have ever thought, it was a good idea to implement constants that way? :omg: Was it possibly done to keep the image size of the executable small?

                                        The good thing about pessimism is, that you are always either right or pleasently surprised.

                                        OriginalGriffO Offline
                                        OriginalGriffO Offline
                                        OriginalGriff
                                        wrote on last edited by
                                        #20

                                        Probably - everything was kept small in those days: we didn't have anywhere near as much disk space as you do cache! If I remember rightly, it was a GEC4070[^] - so the main memory would have been 512Kb - and a dozen users using it...

                                        Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                                        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                                        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                                        1 Reply Last reply
                                        0
                                        • OriginalGriffO OriginalGriff

                                          Well, the good news is it wasn't hidden away in a header file... :omg: If it's any consolation, A FORTRAN compiler I used to work with years, and years ago would accept a constant value as a function parameter, and let you change it at run time. I can't remember FORTRAN syntax any more but it would be similar to:

                                          void MyMethod (ref int i)
                                          {
                                          i = 666;
                                          }
                                          ...
                                          Console.WriteLine(42);
                                          MyMethod(42);
                                          Console.WriteLine(42);

                                          Would happily print: 42 666

                                          Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                                          M Offline
                                          M Offline
                                          mikepwilson
                                          wrote on last edited by
                                          #21

                                          Oh that's some exciting crap right there.

                                          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