Yes - It was me
-
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
-
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
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
-
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
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
-
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
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
-
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
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
-
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
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
-
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
Why didn't you use RAII?
class MutexLocker {
QMutex &m;
public:
MutexLocker(QMutex &qm) : m(qm) { m.lock(); }
~MutexLocker() { m.unlock(); }
}; // classint 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).
-
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
:laugh: :thumbsup: "worst code you'll ever see is the one you wrote last year"
-
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
Manfred R. Bihy wrote:
The compiler should issue a warning or unreachable code. Did it?
Is that what I just ignored... :doh: ;P
-
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
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