It is currently Mon Nov 18, 2019 6:57 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: TypeOf(""),TypeOf(1),TypeOf(1.1), @1, @1.1
PostPosted: Mon Sep 28, 2015 6:40 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 6:41 pm
Posts: 1356
TypeOf("") should return #pb_string
TypeOf(1) should return #pb_quad (because every numeric can be stored in quad)
TypeOf(1.1) should retrun #pb_double (because double can store float-values)

@"something" returns the address of the string, so this
@1 should return the address to a quad with the value 1 (like the string)
@1.1 should return the address to a double with the value 1.1

And maybe
Code:
procedure.a proc()
endprocedure
debug TypeOf(proc())

should return a #pb_procedure

Why?
Code:
Structure vary
  StructureUnion
    a.a
    b.b
    c.c
    d.d
    f.f
    i.i
    l.l
    w.w
    q.q
  EndStructureUnion
EndStructure



Procedure.q _test(t1,*v1.vary)
  Protected ret.vary
  If t1=#PB_Integer     
    ret\i=*v1\i
    Debug "Integer!"+*v1\i   
  ElseIf t1=#PB_Double
    ret\d=*v1\d
    Debug "double!"+*v1\d
  EndIf
  ProcedureReturn ret\q
EndProcedure

Macro test(v1)
  _test(TypeOf(v1),@v1)
EndMacro

a.i=11
b.d=20.5
Debug test(a)
Debug test(b)
debug test(99);<-compilererror


Top
 Profile  
Reply with quote  
 Post subject: Re: TypeOf(""),TypeOf(1),TypeOf(1.1), @1, @1.1
PostPosted: Mon Apr 04, 2016 3:41 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Dec 18, 2004 11:56 am
Posts: 441
Location: Vienna - Austria
+1

For extended macros I'd also like to have the TypeOf-function working (and not failing) for literal string values.
However, imho it should lead to something like "#PB_LiteralString" to not confuse with "#PB_String" ...

Example:
Code:
If (TypeOf("hallo") = #PB_LiteralString) ; This is a literal string

_________________
Go, tell it on the mountains.


Top
 Profile  
Reply with quote  
 Post subject: Re: TypeOf(""),TypeOf(1),TypeOf(1.1), @1, @1.1
PostPosted: Sat Oct 19, 2019 4:38 am 
Offline
Addict
Addict

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 3362
Just tried to make a macro today and was stopped by this. I was surprised to find that TypeOf() doesn't work with literal strings.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye