READ Command problems

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

READ Command problems

Post by blueb »

I read about an issue that the READ command can return unexpected results if not used properly...

see: viewtopic.php?p=525159#p525159

Command: Read[.<type>] <variable>
.<type> should not be optional as the 'default' (.i) can lead to unexpected results.
skywalk wrote:This happens enough that the compiler should throw an error for naked Read's.

Code: Select all

Read.i  <-- Allowed
Read    <-- Error
I agree with Skywalk, even if PB just issued a warning, it would alert the programmer of unexpected results. Besides, with Data.TypeName statement, the Typename is required.
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: READ Command problems

Post by #NULL »

Is there a use case where the Read-type would be different than the variable type? Otherwise it could just be inferred.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: READ Command problems

Post by Fred »

I agree it would be safer to always specify the Read type, like for Data. You can read double data into long variable without any issue for example.
Post Reply