Re: [GD-Windows] forcing value to bool 'true' or 'false' (performance warning)
Brought to you by:
vexxed72
From: Tom H. <to...@3d...> - 2002-04-23 01:27:21
|
At 06:04 PM 4/22/2002, Rich wrote: >Well, the compiler will generate code to convert an int (4 bytes) to a >bool (usually 1 byte), whether or not it matters for performance is >dubious. > >You can eliminate the warning by doing 'bool p = i ? true : false;' Icky. You don't need conditionals for this. When I convert between int and bool I've been using the following to get rid of the warning: bool p = i != 0; or in the case of Win32 API stuff: bool p = i != FALSE; In any case ... the performance issue for most cases is probably minimal. I would only be concerned if I was doing it inside a tight loop that got called a lot and was actually showing up as a spike when profiling. When in doubt, check the assembly. Tom |