To use or not to use bool?

Started by
13 comments, last by Necrosis 22 years, 5 months ago
quote:Original post by Anonymous Poster
bool is just a nice way to look at the int version of true/false states. I like to keep using just ints, then can define TRUE = 1, FALSE = 0. That way can do things like multiply the state, whereas it does not make sense to multiply bool * int.

It doesnt make sense to multiply booleans at all, whether represented by an int or a bool. You get the exact same result by using logical AND on the booleans.



"A society without religion is like a crazed psychopath without a loaded .45"
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Advertisement
quote:Original post by Null and Void
Also, a bool isn't always one byte. It is normally, but the absolute standard doesn't set a size in bytes for any type.


Actually, it does. The C Standard formally specifies that the char, unsigned char, and signed char types are exactly 1 byte long. But you're right about bool, of course.

Edited by - spock on October 24, 2001 11:14:03 AM
i think you should use int instead of bool for return types of funcntions. Lets say that you have a function that does all the direct x initialization. Lets say one thing doesnt work so you return false. Now you have no idea what part of the initilization failed. You know that just part of it failed somewhere. It would be nicer to know what part. With ints you can go this. If it failes at the first part then return 1, second part then return 2.........no failures then return 0;
This way if your game fails then you can tell the client why. You can tell them that "You dont have a hardware accelerated 3D card" or "Your card doesnt support that resolution" instead of just saying "Initialization failure"


"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T
quote:Original post by ncsu121978
...This way if your game fails then you can tell the client why. You can tell them that "You dont have a hardware accelerated 3D card" or "Your card doesnt support that resolution" instead of just saying "Initialization failure"

This is why C++ has exceptions. Use them.
#include &ltexception>//void Initialize_Graphics(void){  HRESULT hr = Direct3D8Create(...);  if FAILED(hr)  {    throw new exception("Failed to create DirectGraphics object.");  }  ...}//// in your WinMain()...  try  {    Initialize_Graphics();    // other init functions  }  catch(exception &e) // catch all errors from preceding try block  {    MessageBox(..., e.what(), ...);  } 
Bah, I'm so stubborn and set in my ways I refuse to switch over to new types.

BOOL? No, bool!
DWORD? No, ulong! (typedef unsigned long ulong)
LPSZx? No! char*!

I should probably NOT do that for my OpenGL library too, but I still do. Portability isn't one of my strongpoints.

Edited by - Omaha on October 28, 2001 1:56:13 AM

This topic is closed to new replies.

Advertisement