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 / A warning about type comparisons

Author
Message
Ratty Rat
23
Years of Service
User Offline
Joined: 24th Sep 2002
Location:
Posted: 30th Apr 2003 14:30
I came across this little oddity using DBPro patch 4 (not sure if its just a patch 4 thing or not).

In the code below I define a simple type, then create 2 variables of that type, the first variable I give a value to, the other I don`t, then I compare them.

Oddly they appear to be neither equal nor not equal. If you add in the commented out line, which sets the second type to an empty string, it works OK.

I suspect the unset type might have an 'UNSET' value (like NULL in a Database) which does not work with comparisons, anyway the rule is 'ALWAYS EXPLICITLY SET VALUES IN TYPES BEFORE DOING COMPARISONS'.
"Don`t try to engage my enthusiasm, I don`t have one"
TheCyborg
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Denmark
Posted: 30th Apr 2003 14:35
Thats odd.. Maybe it's because it is a string... Have you tried doing the same thing with an integer or float?

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Apr 2003 15:44
It's a known issue with strings. All other types are initialised to zero by default.

If you need an explanation of why, I might attempt it later tonight when I get home, but the basic rule of 'initialise everything' solves it anyway.
Ratty Rat
23
Years of Service
User Offline
Joined: 24th Sep 2002
Location:
Posted: 30th Apr 2003 17:39
Ta, good to know its not just me

"Don`t try to engage my enthusiasm, I don`t have one"

Login to post a reply

Server time is: 2026-07-11 22:25:25
Your offset time is: 2026-07-11 22:25:25