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. Yes - It was me

Yes - It was me

Scheduled Pinned Locked Moved The Weird and The Wonderful
ruby
10 Posts 5 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.
  • M Offline
    M Offline
    Marco Bertschi
    wrote on last edited by
    #1

    I produced this little gem, a few months ago:

    QMutex statusMutex;
    int status;
    int GetStatus(){
    statusMutex.lock();
    return status;
    statusMutex.unlock();
    }

    Needles to say that it didn't really work as great as I expected it to :doh: :doh:

    Veni, vidi, caecus

    M A C 3 Replies Last reply
    0
    • M Marco Bertschi

      I produced this little gem, a few months ago:

      QMutex statusMutex;
      int status;
      int GetStatus(){
      statusMutex.lock();
      return status;
      statusMutex.unlock();
      }

      Needles to say that it didn't really work as great as I expected it to :doh: :doh:

      Veni, vidi, caecus

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

      The compiler should issue a warning or unreachable code. Did it? And what with the uninitialised statusMutex thingy? Or is there some background magic going on I'm not privy to? Cheers!

      "I had the right to remain silent, but I didn't have the ability!"

      Ron White, Comedian

      M A 2 Replies Last reply
      0
      • M Manfred Rudolf Bihy

        The compiler should issue a warning or unreachable code. Did it? And what with the uninitialised statusMutex thingy? Or is there some background magic going on I'm not privy to? Cheers!

        "I had the right to remain silent, but I didn't have the ability!"

        Ron White, Comedian

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

        Manfred R. Bihy wrote:

        And what with the uninitialised statusMutex thingy?

        It is initialized - It is Qt code, where objects can be initialized by just writing "ObjectType variablename;". Remember that this is a must for constructors not accepting any parameters - Otherwise they'd be mistaken for method calls, leading the compiler to throw up. And, No - The compiler did not issue a warning or an error, may has something to do with the Qt-Plugin not playing nice to VS 2012.

        Veni, vidi, caecus

        M 1 Reply Last reply
        0
        • M Marco Bertschi

          Manfred R. Bihy wrote:

          And what with the uninitialised statusMutex thingy?

          It is initialized - It is Qt code, where objects can be initialized by just writing "ObjectType variablename;". Remember that this is a must for constructors not accepting any parameters - Otherwise they'd be mistaken for method calls, leading the compiler to throw up. And, No - The compiler did not issue a warning or an error, may has something to do with the Qt-Plugin not playing nice to VS 2012.

          Veni, vidi, caecus

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

          Marco Bertschi wrote:

          It is Qt code, where objects can be initialized by just writing "ObjectType variablename;".

          Interesting, to say the least. What would you do in Qt if you wanted an uninitialised variable declaration? Cheers!

          "I had the right to remain silent, but I didn't have the ability!"

          Ron White, Comedian

          M 1 Reply Last reply
          0
          • M Manfred Rudolf Bihy

            Marco Bertschi wrote:

            It is Qt code, where objects can be initialized by just writing "ObjectType variablename;".

            Interesting, to say the least. What would you do in Qt if you wanted an uninitialised variable declaration? Cheers!

            "I had the right to remain silent, but I didn't have the ability!"

            Ron White, Comedian

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

            Not initialized variables are bad! Nevertheless, go for MyType myObject = 0;. Initialize to 0 because the MS C++ compiler may get a little hiccup if you try it with NULL - Even though it is theoretically valid, MS uses another value which is != 0 for the debug versions to avoid the use of unintilized variables - This behavior may lead to system crashes in the debug version, therefore my first statement.

            Veni, vidi, caecus

            M P 2 Replies Last reply
            0
            • M Marco Bertschi

              Not initialized variables are bad! Nevertheless, go for MyType myObject = 0;. Initialize to 0 because the MS C++ compiler may get a little hiccup if you try it with NULL - Even though it is theoretically valid, MS uses another value which is != 0 for the debug versions to avoid the use of unintilized variables - This behavior may lead to system crashes in the debug version, therefore my first statement.

              Veni, vidi, caecus

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

              Marco Bertschi wrote:

              Not initialized variables are bad!

              I'm an engineer, trust me, I know what I'm adfsadfasdfdfffffffffffffffffffffüllächt! ;P

              "I had the right to remain silent, but I didn't have the ability!"

              Ron White, Comedian

              1 Reply Last reply
              0
              • M Marco Bertschi

                Not initialized variables are bad! Nevertheless, go for MyType myObject = 0;. Initialize to 0 because the MS C++ compiler may get a little hiccup if you try it with NULL - Even though it is theoretically valid, MS uses another value which is != 0 for the debug versions to avoid the use of unintilized variables - This behavior may lead to system crashes in the debug version, therefore my first statement.

                Veni, vidi, caecus

                P Offline
                P Offline
                Pablo Aliskevicius
                wrote on last edited by
                #7

                Why didn't you use RAII?

                class MutexLocker {
                QMutex &m;
                public:
                MutexLocker(QMutex &qm) : m(qm) { m.lock(); }
                ~MutexLocker() { m.unlock(); }
                }; // class

                int GetStatus(){
                MutexLocker tmp(statusMutex);
                return status;
                // destructor unlocks
                }

                Pablo. "Accident: An inevitable occurrence due to the action of immutable natural laws." (Ambrose Bierce, circa 1899). "You are to act in the light of experience as guided by intelligence" (Rex Stout, "In the Best Families", 1950).

                1 Reply Last reply
                0
                • M Marco Bertschi

                  I produced this little gem, a few months ago:

                  QMutex statusMutex;
                  int status;
                  int GetStatus(){
                  statusMutex.lock();
                  return status;
                  statusMutex.unlock();
                  }

                  Needles to say that it didn't really work as great as I expected it to :doh: :doh:

                  Veni, vidi, caecus

                  A Offline
                  A Offline
                  Albert Holguin
                  wrote on last edited by
                  #8

                  :laugh: :thumbsup: "worst code you'll ever see is the one you wrote last year"

                  1 Reply Last reply
                  0
                  • M Manfred Rudolf Bihy

                    The compiler should issue a warning or unreachable code. Did it? And what with the uninitialised statusMutex thingy? Or is there some background magic going on I'm not privy to? Cheers!

                    "I had the right to remain silent, but I didn't have the ability!"

                    Ron White, Comedian

                    A Offline
                    A Offline
                    Albert Holguin
                    wrote on last edited by
                    #9

                    Manfred R. Bihy wrote:

                    The compiler should issue a warning or unreachable code. Did it?

                    Is that what I just ignored... :doh: ;P

                    1 Reply Last reply
                    0
                    • M Marco Bertschi

                      I produced this little gem, a few months ago:

                      QMutex statusMutex;
                      int status;
                      int GetStatus(){
                      statusMutex.lock();
                      return status;
                      statusMutex.unlock();
                      }

                      Needles to say that it didn't really work as great as I expected it to :doh: :doh:

                      Veni, vidi, caecus

                      C Offline
                      C Offline
                      charlieg
                      wrote on last edited by
                      #10

                      Haha - I have the same t-shirt. I earned it late one night trying to debug a release build problem. Had wrapped important code with #ifdef DEBUG..

                      Charlie Gilley You're going to tell me what I want to know, or I'm going to beat you to death in your own house. "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

                      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