Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / default local variables

Author
Message
Spritzen
16
Years of Service
User Offline
Joined: 12th Aug 2009
Location:
Posted: 29th Jun 2011 20:08 Edited at: 29th Jun 2011 20:14
If I set a local variable to 1 what is the default type assigned to it? Integer?

Just curious as I'm using quite a few in various functions and I've not bothered to declare them all as Local and now I come to think of it quite a few are Boolean.

Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 29th Jun 2011 20:49 Edited at: 29th Jun 2011 20:49
They'll be integer. Interesting that it lets you have a variable called Return ?

Spritzen
16
Years of Service
User Offline
Joined: 12th Aug 2009
Location:
Posted: 29th Jun 2011 21:47
Well it was pseudo code, you can't have a variable called return.

I figured as much and I guess the over head from a local variable which is presumably released after the exit of the function is minimal anyway. It was just a curiosity.

Thanks.
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 30th Jun 2011 16:08
I don't think darkbasic has a boolean type. It allows you to set a variable as boolean but I heard internally it is just treated as an integer. I don't know if that's true though.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 30th Jun 2011 17:42
Yeah, I've heard too that all variables you create are still processed as 32-bit variables. Someone posted here a while ago something like this



And you'd see it print the value 255

TheComet

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 30th Jun 2011 18:51
255!?!? (just checked it too)

I wasn't expecting that from a boolean. I did find recently that integers, floats and doubles seems to be the only variable types that offer negative values. To check for -1 on a word I have to check for 65535 instead.

For boolean values I usually set up two constants of TRUE and FALSE, or 1 and 0. Thanks for that, worth noting the error in DBP.

Warning! May contain Nuts!
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 30th Jun 2011 22:00 Edited at: 30th Jun 2011 22:02
Yeah Darkbasic treats a boolean as a byte that only has a range of 0-255. If it was an integer it'd be -2,147,483,648 to 2,147,483,647. When I want a switch that'll be saved as data in a file I just use a byte in the UDT. A switch that has 256 different states is a better switch in my opinion than just ON/OFF.

Here's the datatype ranges:


GregA
15
Years of Service
User Offline
Joined: 21st Jun 2011
Location:
Posted: 30th Jun 2011 23:27
Just a guess, but DBPro was written in C or C++. In c and c++ true is any non zero value, and false is any zero value... That comes from the assembly code instructions JMPZ (jump if compare flag is zero) and JNZ (jump if the compare flag is not zero) is where that originally came from.

This is all iirc... It has been quite a few years since I touched assembly code... Which was one semester in school(I wouldn't even begin to know where to start on the x86 emulators that we call cpu's nowa days), when we had to write the virtual operating system to run on the Vax. I am pretty sure the lesson of that class was two fold... 1. Don't write software in assembly code. 2. Don't write operating systems.

For historical perspective, the last operating system of any relevance to be written in assembly language was OS/2, and just a guess but no one reading this is running OS/2.

Yup pretty sure I strayed off topic there, sorry.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 1st Jul 2011 05:24
8-bit z80, 6502 and the 16-bit 680x0... Those were the days... Reminiscing...

Warning! May contain Nuts!

Login to post a reply

Server time is: 2026-07-10 22:37:40
Your offset time is: 2026-07-10 22:37:40