|
Yes it will work but IIRC it brings up a warning on compilation saying that their is a performance issue when forcing the value to bool.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fuity and sweet. I'm jelly, what am I? - David Williams (Little Britain)
|
|
|
|
|
I have seen this before, and if not commented such it can be misleading. Is there a mistake, i.e. did the programmer intend to use a single "!" ?
It is always better to explicitly state the intended conversion.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fuity and sweet. I'm jelly, what am I? - David Williams (Little Britain)
|
|
|
|
|
V. wrote:
Colleagues told me the "!!" was to make sure it was 0 or 1 false or true.
Is this so?
Yes, that's what it does. It's also very portable, whereas static_cast and bool are not.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
sorry but the static_cast keyword is part of the C++ language... portable so.
for the portability of bool , i agree. We should prefer BOOL instead...
TOXCCT >>> GEII power
|
|
|
|
|
toxcct wrote:
sorry but the static_cast keyword is part of the C++ language... portable so.
Maybe on the newer compilers, but not on the ones I started with. It's also not available in C. The point was that !! will work across the board whereas static_cast and bool will not.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
ok if you want to port code from C++ to C... but you'll probably encounter many other problems...
TOXCCT >>> GEII power
|
|
|
|
|
but BOOL would in turn go into the whole idea of a boolean (only true/false)
if I'm not mistaken takes a bool less memory then a BOOL (in Java it is so I think), but then again maybe not.
but that would take us too far...
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
why BOOL would take more memory than a bool ??
one byte doesn't it ?
TOXCCT >>> GEII power
|
|
|
|
|
Is a BOOL 1 Byte? I thought it was of size equal to an integer (cause 1,2,3,4,5,6,... = TRUE) bool doesn't know 0,1,2,3,4,...
bool is for certain 1 byte,
don't know about BOOL
Not really important when working with enough memory
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
BOOL is an "int" and can have the same values as an int.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
BOOL is 4 bytes on 32-bit systems.
bool, on the other hand, is 1 byte.
Bikram Singh
|
|
|
|
|
oh... why not.
and can we have an evidence of what you are telling us ?
TOXCCT >>> GEII power
|
|
|
|
|
Fire up Visual C++ and run this code.
<br />
#include "stdafx.h"<br />
#include <conio.h><br />
#include <windows.h><br />
<br />
int main(int argc, char* argv[])<br />
{<br />
printf("\nbool = %u",sizeof(bool));<br />
printf("\nBOOL = %u",sizeof(BOOL));<br />
getch();<br />
return 0;<br />
}<br />
Bikram Singh
|
|
|
|
|
i have many more interesting things to do instead...
perhaps also you wanted to write <stdio.h> and <conio.h> ??
but, ok, that's an evidence
TOXCCT >>> GEII power
|
|
|
|
|
yup, i did. first time i've posted a #include statement.
<conio.h>
Bikram Singh
|
|
|
|
|
toxcct wrote:
perhaps also you wanted to write <stdio.h> and <conio.h> ??
They're there. Look closely!
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
DavidCrow wrote:
They're there
hem, maybe they are too big and i'm too close...
TOXCCT >>> GEII power
|
|
|
|
|
What David means is, look at the page's source code...
"look closely", "read between the lines" etc... get it ?
Bikram Singh
|
|
|
|
|
toxcct wrote:
for the portability of bool, i agree. We should prefer BOOL instead...
no, BOOL is MS-specific, bool is ANSI C++. Also, you should always compare via similar types, so a correct form of the original (according to my profiler) would be:
bool bAllowUnvalidateTextResult = (siteFlags.GetNbrValue(ALLOW_UNVALIDATE_TEXTRESULT) == 1) ? true : false;
that is, if GetNbrValue returns an int .
~Nitron.
ññòòïðïðB A start
|
|
|
|
|
Nitron wrote:
bool is ANSI C++
yes. int too. and to prevent any change between architectures, the types ares redefined to be similar on every systems. that's called portability
Nitron wrote:
Also, you should always compare via similar types
but the implicit casts also exist ! i only said that my code line was working. i never said it was the best !
TOXCCT >>> GEII power
|
|
|
|
|
toxcct wrote:
i only said that my code line was working. i never said it was the best !
I know, and I do it too, what I was saying was that my Parasoft C++ Test profiler says it's bad practice, but hey, what do profilers know
~Nitron.
ññòòïðïðB A start
|
|
|
|
|
What if GetNbrValue() returns 2? Do all non-zero values indicate true?
How about:
bool bAllowUnvalidateTextResult = (siteFlags.GetNbrValue(ALLOW_UNVALIDATE_TEXTRESULT) == 0) ? false : true;
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
atenshun to detale!
i like, i like!
Bikram Singh
|
|
|
|
|
bool a = b != 0;
That works just fine and IMHO is much clearer.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I've a got a problem using a MsFlexGrid control in a CDialogBar window.
I've developed a new class derived from CDialogBar in order to manage the DialogBar window.
My project is a MDI and the instance of my class (derived from CDialogBar) belongs to CMainFrame class.
My problem is the following:
- the MsFlexGrid control doesn't receive any user interface event (scroll up, scroll down, onbutton, and so on....). When the main window is shown, and the DialogBar is shown within it, the user can't manage the MsFlexGrid control: in example, clicking on scroll bar buttons doesn't have any effect.
I think I need to write some code in CMainFrame class in order to let it map all MsFlexGrid control windows messages, but I don't know how to do it !
I'm able to do it for other controls like buttons, listboxes and so on... but I think is not the same for MsFlexGrid. For that kind of controls I use the following code in CMainFrame:
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)<br />
ON_BN_CLICKED(IDC_BTN_MY_BUTTON, CDlgbarMyDialogBar::OnBtnMyButton)<br />
END_MESSAGE_MAP()
But I'm almost sure it is not the same for the MSFlexgrid. By the way I don't need to write any code to let a listbox work in a CDialogBar...
so, can someone help me ?
Thank you very much !
|
|
|
|