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

    Sander RosselS Offline
    Sander RosselS Offline
    Sander Rossel
    wrote on last edited by
    #14

    I've unwillingly sent millions of $ to my private bank account because O looked a lot like 0! Well, that's what I'll tell the judge when they find out ;p

    It's an OO world.

    public class Naerling : Lazy<Person>{
    public void DoWork(){ throw new NotImplementedException(); }
    }

    1 Reply Last reply
    0
    • L lewax00

      if (1 == 2)
      {
      throw new UniverseBorkedException("you're pretty much f***ed elephanted.");
      }

      M Offline
      M Offline
      Manfred Rudolf Bihy
      wrote on last edited by
      #15

      Not f***ed, but rather elephanted or maybe pachydermed. Cheers!

      "With sufficient thrust, pigs fly just fine."

      Ross Callon, The Twelve Networking Truths, RFC1925

      "Der Berg ruft!"

      Me, 2012-05-24

      L 1 Reply Last reply
      0
      • M Manfred Rudolf Bihy

        Not f***ed, but rather elephanted or maybe pachydermed. Cheers!

        "With sufficient thrust, pigs fly just fine."

        Ross Callon, The Twelve Networking Truths, RFC1925

        "Der Berg ruft!"

        Me, 2012-05-24

        L Offline
        L Offline
        lewax00
        wrote on last edited by
        #16

        Of course, how could I be so foolish?

        1 Reply Last reply
        0
        • W wizardzz

          Pfft, what an idiot. We all know msdn recommends using 23 = 33, or even 23 = 12. http://msdn.microsoft.com/en-us/library/215yacb6(v=vs.71).aspx[^]

          M Offline
          M Offline
          Matthew Dennis
          wrote on last edited by
          #17

          or 9 x 6 = 42

          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?

            G Offline
            G Offline
            greldak
            wrote on last edited by
            #18

            In VB that expression will always resolve to False 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. Its not something I would expect to see as a simple expression but it can be useful as a clause especially if you need to build up a complex expression at run time. In practice its more likely that some piece of funcionality is wanted to remain in the codebase but not required to run under normal circumstances - probably debug code although there are better ways of doing it.

            S 1 Reply Last reply
            0
            • G greldak

              In VB that expression will always resolve to False 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. Its not something I would expect to see as a simple expression but it can be useful as a clause especially if you need to build up a complex expression at run time. In practice its more likely that some piece of funcionality is wanted to remain in the codebase but not required to run under normal circumstances - probably debug code although there are better ways of doing it.

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

              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 K 2 Replies Last reply
              0
              • M Matthew Dennis

                or 9 x 6 = 42

                S Offline
                S Offline
                Sucramsy
                wrote on last edited by
                #20

                If 42 is the answer to life the universe and everything then this statement would be true.

                1 Reply Last reply
                0
                • A AspDotNetDev

                  I just came across this code written by a coworker:

                  If 1 = 2 Then

                  Seems silly; probably a way to temporarily block out some code or something of that sort. However, it made me wonder why there aren't more people taking advantage of a potential easter egg. When I typed in "2+2" into Google and WolframAlpha, they both replied with "4". :((

                  Thou mewling ill-breeding pignut!

                  R Offline
                  R Offline
                  reilly96
                  wrote on last edited by
                  #21

                  in SQL I use that to create tables with no data

                  select *
                  into #t
                  from table1
                  where 1=2

                  A 1 Reply Last reply
                  0
                  • 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