Re: bool vs. BOOL

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



The first version should produce a warning if your warning settings are high
enough.

The reason is that the C compiler will automatcially generate code similar
to your second version and so you get a performance warning since code is
generated that may not be immediately obvious from looking at the source.

Either is ok as far as the resulting logic.

BTW, why not just

bool MyMethod()
{
return (bool)DeviceIoControl(...);
}

or (to eliminate the warning):


bool MyMethod()
{
return (DeviceIoControl(...) != 0);
}

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com


"VFaul" <VFaul@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:59B2C3BE-A4F7-4B09-ACA2-C0AF5F95EC1B@xxxxxxxxxxxxxxxx
I have many methods that return type bool. In the method I'm calling a
Microsoft method that returns BOOL. I want to return the result of the
Microsoft method as shown below.

bool MyMethod()
BOOL bOk = DeviceIoControl(...);
return (bool) bOk;

Is there a problem with return (bool) bOk;, or do I need to do the
following?

if (bOk)
return true;
else
return false;

I prefer not to change my method return type because of all the changes I
will have to make.

--
VFaul


.



Relevant Pages

  • Re: bool vs. BOOL
    ... Actually bOk!= FALSE is more correct, and what I use all the time. ... bool MyMethod() ... Microsoft method that returns BOOL. ...
    (microsoft.public.vc.mfc)
  • Re: bool vs. BOOL
    ... "Jonathan Wood" wrote: ... bool MyMethod() ... Microsoft method that returns BOOL. ... BOOL bOk = DeviceIoControl; ...
    (microsoft.public.vc.mfc)
  • Re: gratuitous gcc warnings: unused function arguments?
    ... > I'm not sure what is required to disable this warning, ... The second error message is only generated when GCC thinks it ... someone else (hopefully a GCC expert/language pedant :-) second guess whether ... bool warn_unused_variable; ...
    (freebsd-current)
  • lisp toy: strangest warning Ive seen
    ... Can anyone shed light upon this warning. ... number it refers to the anonymous union, ... int cari; ... bool init() { ...
    (comp.lang.c)
  • Re: bool vs. BOOL
    ... Microsoft method that returns BOOL. ... bool MyMethod() ... BOOL bOk = DeviceIoControl; ...
    (microsoft.public.vc.mfc)