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. Missed Opportunity for Easter Egg

Missed Opportunity for Easter Egg

Scheduled Pinned Locked Moved The Lounge
com
32 Posts 20 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.
  • OriginalGriffO OriginalGriff

    Oh yes! I remember making that mistake - it took ages to find before I realized that my constant values had changed... Trouble was,

    1=2

    looked a lot like

    I=2

    :doh:

    Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

    O Offline
    O Offline
    onemorechance
    wrote on last edited by
    #22

    OriginalGriff wrote:

    ... my constant values had changed...

    Something about that just doesn't seem right ...

    OriginalGriffO 1 Reply Last reply
    0
    • T TheGreatAndPowerfulOz

      AspDotNetDev wrote:

      If 1 = 2 Then

      In old-school Fortran this was a real potential. Certain integers were stored at memory locations, then you could say 1 = 2 (assign the value 2 to where the value 1 is stored). Then statements like

      if 1 = 2 then ...

      would be 'valid'.

      If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
      You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun

      E Offline
      E Offline
      ekolis
      wrote on last edited by
      #23

      You can do that in Java as well, though it requires boxing conversions...

      1 Reply Last reply
      0
      • O onemorechance

        OriginalGriff wrote:

        ... my constant values had changed...

        Something about that just doesn't seem right ...

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

        That's why it took so long to work it out - it's just not something you expect... :laugh:

        Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

        "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
        • R reilly96

          in SQL I use that to create tables with no data

          select *
          into #t
          from table1
          where 1=2

          A Offline
          A Offline
          AspDotNetDev
          wrote on last edited by
          #25

          Neat trick. :thumbsup:

          Thou mewling ill-breeding pignut!

          1 Reply Last reply
          0
          • S svella

            greldak wrote:

            In other languages (C included) you could overload the values for 1 and 2 and/or the operator = or command If
            Good luck figuring out whats going on with that level of obfuscation.

            I'm pretty sure you're wrong about being able to override either the values or the operator in C (or even C++ for that matter), but I'd welcome a working example.

            K Offline
            K Offline
            Kostya Kovalskyy
            wrote on last edited by
            #26

            compiles on GCC

            #define if(X) if(1)

            using namespace std;

            int main()
            {
            if (1 == 2) {
            cout << "this is executed" << endl;
            }
            return 0;
            }

            this would compile on C compiler too, but I just hate using those printfs. But you were right about #defining numbers -- it's impossible. A define identifier name cannot start with a number. But you can overload almost anything else.

            S 1 Reply Last reply
            0
            • K Kostya Kovalskyy

              compiles on GCC

              #define if(X) if(1)

              using namespace std;

              int main()
              {
              if (1 == 2) {
              cout << "this is executed" << endl;
              }
              return 0;
              }

              this would compile on C compiler too, but I just hate using those printfs. But you were right about #defining numbers -- it's impossible. A define identifier name cannot start with a number. But you can overload almost anything else.

              S Offline
              S Offline
              svella
              wrote on last edited by
              #27

              Hmmm, yeah, well what you've really done is macro replaced an "if" expression (not really overloaded it in the normal sense of the word, but I guess close enough), but have not really succeeded in overloading 1, 2, or ==.

              K 1 Reply Last reply
              0
              • S svella

                Hmmm, yeah, well what you've really done is macro replaced an "if" expression (not really overloaded it in the normal sense of the word, but I guess close enough), but have not really succeeded in overloading 1, 2, or ==.

                K Offline
                K Offline
                Kostya Kovalskyy
                wrote on last edited by
                #28

                Even through it does not really "overload" it, it can still lead to a lot of confusion. In C++ you can also do something like this

                #include

                class T {
                public:
                int a;
                T(int _a) : a(_a) {}
                bool operator==(const T &var) {return true;}
                };

                using namespace std;

                int main() {
                #define int T //this is defined here because main returns int, and this causes error if defined earlier
                int a = 1, b = 2;
                if (a == b) {
                cout << "this is evaluated" << endl;
                }
                return 0;
                }
                }

                Of course, you can always put anything in the == operator so it would behave differently :)

                K 1 Reply Last reply
                0
                • K Kostya Kovalskyy

                  Even through it does not really "overload" it, it can still lead to a lot of confusion. In C++ you can also do something like this

                  #include

                  class T {
                  public:
                  int a;
                  T(int _a) : a(_a) {}
                  bool operator==(const T &var) {return true;}
                  };

                  using namespace std;

                  int main() {
                  #define int T //this is defined here because main returns int, and this causes error if defined earlier
                  int a = 1, b = 2;
                  if (a == b) {
                  cout << "this is evaluated" << endl;
                  }
                  return 0;
                  }
                  }

                  Of course, you can always put anything in the == operator so it would behave differently :)

                  K Offline
                  K Offline
                  Kostya Kovalskyy
                  wrote on last edited by
                  #29

                  If you want to only "subtly" mess it up, and work for most of other cases normally you can do this:

                  #include

                  class T {
                  public:
                  int a;
                  T(int _a) : a(_a) {}
                  bool operator==(const T &var) {
                  if((a == 1 && var.a == 2) || (a == 2 && var.a == 1)) return true;
                  else return a == var.a;
                  }
                  };

                  using namespace std;

                  int main() {
                  #define int T //this is defined here because main returns int, and this causes error if defined earlier
                  int a = 1, b = 2;
                  if (a == b) cout << "this is evaluated";
                  a = 4, b = 5;
                  if (a == b) cout << "while this is not" << endl;
                  return 0;
                  }

                  S 1 Reply Last reply
                  0
                  • N Nueman

                    True. But he is coding in vb. In that world anything can happen. ;P

                    What me worry?

                    K Offline
                    K Offline
                    Keith Badeau
                    wrote on last edited by
                    #30

                    :laugh: :thumbsup:

                    1 Reply Last reply
                    0
                    • S svella

                      greldak wrote:

                      In other languages (C included) you could overload the values for 1 and 2 and/or the operator = or command If
                      Good luck figuring out whats going on with that level of obfuscation.

                      I'm pretty sure you're wrong about being able to override either the values or the operator in C (or even C++ for that matter), but I'd welcome a working example.

                      K Offline
                      K Offline
                      Keith Badeau
                      wrote on last edited by
                      #31

                      In C++ you can override operators inside of a class.

                      class foo
                      {
                      private:
                      int num;

                      public:
                      foo* operator=(int i) {
                      this->num = i;
                      return this;
                      }
                      // ...
                      };

                      I believe the example is syntactically correct and it is a very contrived an arbitrary example. Numbers cannot be overloaded (In Scheme maybe?) and new operators cannot be created that do not already exist. In C operators cannot be overloaded.

                      1 Reply Last reply
                      0
                      • K Kostya Kovalskyy

                        If you want to only "subtly" mess it up, and work for most of other cases normally you can do this:

                        #include

                        class T {
                        public:
                        int a;
                        T(int _a) : a(_a) {}
                        bool operator==(const T &var) {
                        if((a == 1 && var.a == 2) || (a == 2 && var.a == 1)) return true;
                        else return a == var.a;
                        }
                        };

                        using namespace std;

                        int main() {
                        #define int T //this is defined here because main returns int, and this causes error if defined earlier
                        int a = 1, b = 2;
                        if (a == b) cout << "this is evaluated";
                        a = 4, b = 5;
                        if (a == b) cout << "while this is not" << endl;
                        return 0;
                        }

                        S Offline
                        S Offline
                        svella
                        wrote on last edited by
                        #32

                        Yep, I'm aware of operator overloading and all the attendant mischief possible with it. But I stand by my original statement, that given the original expression 1 == 2, there is no way in C or C++ to overload the values of the integer literals nor is there a way to redefine the meaning of == in a way that would affect it's meaning when used on those literals. But as you cleverly pointed out, you can use the macro processor to redefine if in such a way as to eliminate the expression before the compiler ever sees it.

                        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