Advertisement
Mysoft

Untitled

Apr 3rd, 2024
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. type x
  2.   x as long
  3. end type
  4.  
  5.  
  6. 'variable named "x", having "x" as type
  7. 'this is fine since despite having the same names they are not used in the same contexts
  8. dim shared as x x
  9. dim shared as long y
  10.  
  11. sub MySub( x as long )    
  12.   dim as integer y = 5
  13.   print "y=";y,".y=";.y  
  14.   print "parm x=";x,"old x.x=";.x.x
  15.   .x.x = x
  16.   print "parm x=";x,"new x.x=";.x.x
  17. end sub
  18.  
  19. scope 'main
  20.  
  21.   'setting global x heres...
  22.   y = 10
  23.   x.x = 12
  24.  
  25.   'declared a "x" as string which is fine since this is a different scope
  26.   dim as string x = "hello world"
  27.  
  28.   'freebasic kinda screwed up in this case... because sizeof() should refer to type X as priority
  29.   'and len(x) should refer to variable x.. as priority.... but they don't
  30.   print "sizeof(x)=";sizeof(x) 'this will cause a warn due to ambiguity (and will show the size of the struct)
  31.   print "len(x)=";len(x)       'this will cause a warn due to ambiguity (and will show the size of the struct)
  32.  
  33.   print sizeof(.x)  'this will NOT WARN and show the size of the struct
  34.   print sizeof(..x) 'this will NOT WARN and show the size of the struct
  35.   print sizeof(*@x) 'this will NOT WARN and show the size of the variable (12 since that's the size of the string descriptor)
  36.   print len(*@x)    'this will NOT WARN and show the LENGTH of the string variable
  37.  
  38.   MySub(15)
  39.   sleep
  40. end scope
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement