Page 1 of 1
Select + Case + Default + EndSelect
Posted: Sat May 14, 2011 11:59 pm
by 4RESTER
What wrong in this code?
Code: Select all
Global BPB_Media.B = $F8
Select BPB_Media.B
Case $F0,$F8 To $FF
Debug "BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
Default
Debug "Wrong BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
EndSelect
In fact, with such value
BPB_Media.B = $F8
the branch of Default shall not be executed.
Re: Select + Case + Default + EndSelect
Posted: Sun May 15, 2011 12:08 am
by gnasen
no, its correct, because in PB most variables are signed:
Byte: -128 to +127
So if you store $F8 = 248 in a byte, you get: -8. Use this instead:
Char (= unsigned Byte): 0 to 255
Code: Select all
Global BPB_Media.c = $F8
Select BPB_Media.c
Case $F0,$F8 To $FF
Debug "BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
Default
Debug "Wrong BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
EndSelect
Re: Select + Case + Default + EndSelect
Posted: Sun May 15, 2011 12:10 am
by netmaestro
.c is 16 bits in unicode mode, better use .a for unsigned byte.
Re: Select + Case + Default + EndSelect
Posted: Sun May 15, 2011 12:11 am
by 4RESTER
gnasen wrote:no, its correct, because in PB most variables are signed:
Byte: -128 to +127
So if you store $F8 = 248 in a byte, you get: -8. Use this instead:
Code: Select all
Global BPB_Media.c = $F8
Select BPB_Media.c
Case $F0,$F8 To $FF
Debug "BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
Default
Debug "Wrong BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
EndSelect
Hmmm, very strange behavior of the compiler.
So literal $F8 must be also be as -8

Re: Select + Case + Default + EndSelect
Posted: Sun May 15, 2011 12:12 am
by Demivec
4RESTER wrote:What wrong in this code?
Code: Select all
Global BPB_Media.B = $F8
Select BPB_Media.B
Case $F0,$F8 To $FF
Debug "BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
Default
Debug "Wrong BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
EndSelect
In fact, with such value
BPB_Media.B = $F8
the branch of Default shall not be executed.
Same as the posting in your other thread. When the hexadecimal literals are converted to decimal it would read this way:
Code: Select all
Global BPB_Media.B = -8 ;$F8
Select BPB_Media.B
Case 240, 248 To 255 ;$F0,$F8 To $FF
Debug "BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
Default
Debug "Wrong BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
EndSelect
Which clearly shows the default case will be executed.
Use this code to prove it to yourself:
Code: Select all
Global BPB_Media.B = $F8
Select BPB_Media.B
Case $F0,$F8 To $FF
Debug "BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
Case -8
Debug "Right BPB_Media: " + Str(BPB_Media)
Default
Debug "Wrong BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
EndSelect
Re: Select + Case + Default + EndSelect
Posted: Sun May 15, 2011 12:20 am
by gnasen
netmaestro wrote:.c is 16 bits in unicode mode, better use .a for unsigned byte.
Ah thanks, I missed that. I never used Unicode until now

Re: Select + Case + Default + EndSelect
Posted: Sun May 15, 2011 12:24 am
by 4RESTER
Demivec wrote:4RESTER wrote:What wrong in this code?
Code: Select all
Global BPB_Media.B = $F8
Select BPB_Media.B
Case $F0,$F8 To $FF
Debug "BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
Default
Debug "Wrong BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
EndSelect
In fact, with such value
BPB_Media.B = $F8
the branch of Default shall not be executed.
Same as the posting in your other thread. When the hexadecimal literals are converted to decimal it would read this way:
Code: Select all
Global BPB_Media.B = -8 ;$F8
Select BPB_Media.B
Case 240, 248 To 255 ;$F0,$F8 To $FF
Debug "BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
Default
Debug "Wrong BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
EndSelect
Which clearly shows the default case will be executed.
Use this code to prove it to yourself:
Code: Select all
Global BPB_Media.B = $F8
Select BPB_Media.B
Case $F0,$F8 To $FF
Debug "BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
Case -8
Debug "Right BPB_Media: " + Str(BPB_Media)
Default
Debug "Wrong BPB_Media: $"+RSet(Hex(BPB_Media, #PB_Byte),2,"0")
EndSelect
Looks like this dialect of BASIC is a finding for CodeTalkers (NavajoBasic).
Re: Select + Case + Default + EndSelect
Posted: Sun May 15, 2011 12:51 am
by 4RESTER
netmaestro wrote:.c is 16 bits in unicode mode, better use .a for unsigned byte.
Okay.
8-bits unsigned as .A
16-bits unsigned as .U
What about 32-bits
UNSIGNED values?
Re: Select + Case + Default + EndSelect
Posted: Sun May 15, 2011 1:31 am
by luis
They have been requested (see in the appropriate subforum) but the official answer for the team, if I recall correctly (please correct me if I'm wrong), is the .a and .u were added as a convenience for working with ascii/unicode, and no larger unsigned data type are planned.
Obviously is possible to work with signed integers just the same, but I would like a 32 byte unsigned type too, for what it's worth. Especially to work with c/c++ libraries in a simpler way.
edit: found the post I was mentioning
http://www.purebasic.fr/english/viewtop ... 80#p295680