Funny thing with TYPEOF

General FreeBASIC programming questions.
Post Reply
SARG
Posts: 1763
Joined: May 27, 2005 7:15
Location: FRANCE

Funny thing with TYPEOF

Post by SARG »

Code: Select all

#print typeof(sht)  ''error and a type is printed

#if TypeOf(sht) = TypeOf(Integer)   ''no error 
	#print "I'm an integer even if I don't exist"
#else
	#print "I don't exist"
#endif
output :

Code: Select all

FBTEMP.bas(3) error 42: Variable not declared, sht in '#print typeof(sht)'
INTEGER
I don't exist
Lost Zergling
Posts: 538
Joined: Dec 02, 2011 22:51
Location: France

Re: Funny thing with TYPEOF

Post by Lost Zergling »

Or with # ? ;-)
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: Funny thing with TYPEOF

Post by srvaldez »

hello SARG :)
it works as expected with the latest Git repo, the first line gives the expected error, if commented-out then it just prints "I don't exist", it doesn't print INTEGER here
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Funny thing with TYPEOF

Post by fxm »

Why not return 'ANY' for 'TYPEOF(unknown)' ?
SARG
Posts: 1763
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Funny thing with TYPEOF

Post by SARG »

srvaldez wrote: Jun 23, 2022 13:21 hello SARG :)
it works as expected with the latest Git repo, the first line gives the expected error, if commented-out then it just prints "I don't exist", it doesn't print INTEGER here
Hi srvaldez
First line there is an error but not with #if and there is also the INTEGER printed.
In my opinion it should not work like that.

@fxm
#print should be discarded instead output something wrong as no information is available
Post Reply