Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a form of BOOL for FreeBASIC or will there ever be
#1
c++ programmers will be familiar with bools. And Example would be

Code:
int x
x = 10
int y
y = 10

bool b
b = (x == y)

b will then equal "True". Is there anything like this for freebasic?
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
#2
No, there is not.

And I think v1c said there would never be.

You can use:
Code:
dim a as integer
x = 10
y = 11
a = (x = y)
print a
Reply
#3
Or do this:

Code:
Const false = 0
Const true = Not false

Dim a as byte
a = true

Whenever I made anything in QB, I almost always defined those two constants. :wink:
Reply
#4
or you can do this:

Code:
enum bool
   false = 0
   true = -1
end enum

dim b as bool

b = (1 = 1)
print b

if b = true then
    print "works"
end if

sleep
And don't get misleaded, in C/C++ boolean datatype is just an integer as well
url]http://fbide.sourceforge.net/[/url]
Reply
#5
Last time i checked most compilers now have bool as a string.

so

Code:
int main ();

{
int x;
x = 10;
int y;
y = 10;

bool b;
b = (x == y);
cout << b <<; \\i'm not sure if the end << are neccasary or not
system ("PAUSE");
return;
}

would display TRUE on the screen. I think this should work, i've not use c++ to know it off by heart (yet).
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
#6
If classes are ever implemented, it will not be hard to make the kind of bool you're looking for. Until then it's kinda useless anyways Tongue
Reply
#7
Ah well, are classes and objects ever going to be added to freeBASIC, it'd make a lot of c++ libaries useable that weren't previously compatible with fb.
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
#8
vic's working on it, but it might take awhile.
Reply
#9
my code was mistaken:

Code:
int main (bool b, int x, int y)

{
x = 10;  
y = 10;

b = (x == y);

cout << b << "\n";

system ("PAUSE");
return b;
}

DEV-CPP still uses the old 1 or 0 for true and false, but most c++ compilers nowadays use true and false (well, thats what i've been told anyway)
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
#10
There is no point in using 1-bit integers. The CPU handles 32 bits at a time, it's just silly to have boolean arithmatic. and wasteful.

#define -1 true
#define 0 false

that'll do it. QB (and probably FB) comparisons return either -1 or 0.

As for strings:
Code:
function bool(x as integer) as string
if x = 0 then return "false"
return "true"
end function
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)