len/sizeof parse their argument as type first, then if that fails, as expression. The problem is that the type parsing will eat any namespace prefix in the hopes it is an access to a namespaced type, and if that fails, the expression parser is called without getting to see that namespace prefix. So it's just lost.
That causes the "variable not declared
" errors in code like this:
namespace UDT dim shared i as integer end namespace print sizeof( UDT.i )
As a work-around it's possible to use parentheses, because then the type parser will immediately see that it's not a type, and then it will exit without having eaten the namespace prefix:
print sizeof( (UDT.i) )
Another example:
namespace foo const bar = "whee" end namespace print len(foo.bar)
A workaround is to use double parentheses:
print len((foo.bar))
Same problem with the keywords 'Typeof()' or 'Sizeof()'.
Referring to forum at post:
http://www.freebasic.net/forum/viewtopic.php?p=194125#p194125
Diff:
Diff:
Similar problem:
Why Len(), Sizeof() and Typeof() do not work with non-static members from TYPE/UNION?
Referring to forum at post:
http://www.freebasic.net/forum/viewtopic.php?p=208096#p208096
See also to the new feature request:
http://sourceforge.net/p/fbc/feature-requests/293/
Last edit: fxm (freebasic.net) 2015-05-29
Fixed in https://github.com/freebasic/fbc/pull/201
Commit in [62fdd4]
Some simple tests have been added to test suite for 'plain' uses of namespaces, nested namespaces, types, etc.
Related
Commit: [62fdd4]