Specifically I'm noticing that
1) #print and #error do not allow for token resolution unless that token is at the very beginning of the line.
2) The wiki description of typeof() is clearly omitting something about its actual behavior. The wiki states the following:
But this "compiler intrinsic" does not behave like other compiler intrinsics (See other intrinsics: https://www.freebasic.net/wiki/CatPgDddefines) as it does not actually replace itself with the type of the variable passed to it in some circumstances.Typeof is a compiler intrinsic that replaces itself with the type of the variable passed to it.
I've noted the issues in the following code snippet:
Code: Select all
#define _TEST asdf
dim _TEST as integer
'Let's see if we can output details on both the
'variable being used, and its type...
'_TEST is not resolved in either instances.
'typeof is not resolved either
#print Variable: _TEST is of type typeof(_TEST)
'Nope
#print Variable: ##_TEST is of type typeof(##_TEST)
'Closer, but typeof is still not resolved
'This is rather excessive for an only partially working solution
__FB_UNQUOTE__(__FB_EVAL__("#print Variable: " & __FB_QUOTE__(_TEST) & " is of type " & __FB_QUOTE__(typeof(_TEST))))
'This is the most straightforward, minimal solution, but
'why does it have to be spread across 3 lines?
'This could be partially joined with the above solution
'for a 2 line solution but damn is it ugly.
#print Variable:
#print _TEST is of type
#print typeof(_TEST) 'Demands its own line because...? It's special I guess
'Syntax error. I'm not sure why, seems like it should be valid to me.
'#print __FB_EVAL__(typeof(_TEST))
'End-of-line what now? This is both unexpected and bizarre.
'#print typeof(_TEST) should be an integer
'Cannot capture the actual type name in quotes because...?
'I would expect this to output "INTEGER", not "typeof(asdf)"
'AND JUST WHY is _TEST being resolved here but it wasn't being
'resolved above in the first couple examples??
#print __FB_QUOTE__(typeof(_TEST))
Also are any of the noted issues with typeof() a bug or am I just using it wrong?