Posts: 677
Threads: 57
Joined: Jan 2005
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/]
[/url]
Posts: 3,522
Threads: 189
Joined: Dec 2003
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
Posts: 142
Threads: 6
Joined: Aug 2001
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:
Posts: 658
Threads: 71
Joined: Sep 2003
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]
Posts: 677
Threads: 57
Joined: Jan 2005
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/]
[/url]
Posts: 122
Threads: 6
Joined: Feb 2002
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
Posts: 677
Threads: 57
Joined: Jan 2005
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/]
[/url]
Posts: 979
Threads: 27
Joined: Aug 2001
vic's working on it, but it might take awhile.
Posts: 677
Threads: 57
Joined: Jan 2005
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/]
[/url]
Posts: 979
Threads: 27
Joined: Aug 2001
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