Should we now disallow 'SIZEOF(array_name)' and 'LEN(array_name)' ?
Already there is a note (warning) in the documentation on the use of 'Sizeof(array_name)' recommending against its use, but rather the use of 'Sizeof(array_element)'.
But even more the use of 'Len(array_name)' which is allowed (for the moment without a note in the documentation) is even more misleading because it actually always returns the value of 'Sizeof(array_element)' !
In addition, at the array level, there are now (since fbc version 1.09.0) the functions 'FB.ArrayLen()' and 'FB.ArraySize()' which are, for their part, consistent with their names.
I think it is now time to disallow these 2 syntaxes : 'Sizeof(array_name)' and 'Len(array_name)'.
Also remember to take into account at the same time the bug report:
"#821 LEN() and SIZEOF() should not be allowed when used with bitfields"
https://sourceforge.net/p/fbc/bugs/821/
Example grouping together all these cases of inconsistent LEN/SIZEOF values, highlighted by ">>> value <<<":
#if __FB_VERSION__ >= "1.09.0"
#include once "fbc-int/array.bi"
#endif
Scope
Dim As Zstring * 5 s(1 To...) = {"1", "12", "123"}
Print "SIZED ARRAY : 'Dim As Zstring * 5 s(1 To...) = {""1"", ""12"", ""123""}'"
Print "Len(s(1))", "Len(s(2))", "Len(s(3))", "Len(s)", "Len(Typeof(s))"
Print Len(s(1)), Len(s(2)), Len(s(3)), ">>> " & Len(s) & " <<<", Len(Typeof(s))
Print "Sizeof(s(1))", "Sizeof(s(2))", "Sizeof(s(3))", "Sizeof(s)", "Sizeof(Typeof(s))"
Print Sizeof(s(1)), Sizeof(s(2)), Sizeof(s(3)), ">>> " & Sizeof(s) & " <<<", Sizeof(Typeof(s))
#if __FB_VERSION__ >= "1.09.0"
Print "FB.Arraylen(s())"
Print FB.Arraylen(s())
Print "FB.Arraysize(s())"
Print FB.Arraysize(s())
#endif
Print
End Scope
Scope
Dim As Zstring * 5 s()
Print "UNSIZED ARRAY : 'Dim As Zstring * 5 s()'"
Print "Len(s(0))", "Len(s)", "Len(Typeof(s))"
Print Len(s(0)), ">>> " & Len(s) & " <<<", Len(Typeof(s))
Print "Sizeof(s(0))", "Sizeof(s)", "Sizeof(Typeof(s))"
Print Sizeof(s(0)), ">>> " & Sizeof(s) & " <<<", Sizeof(Typeof(s))
#if __FB_VERSION__ >= "1.09.0"
Print "FB.Arraylen(s())"
Print FB.Arraylen(s())
Print "FB.Arraysize(s())"
Print FB.Arraysize(s())
#endif
Print
End Scope
Sleep
I think the current behaviour should be changed. It would be nice if
len(array)andsizeof(array)would return length and size of an array if the result is known to be constant at compile time. However, that might be confusing for users if the behaviour changes from fbc version to the next. So perhaps disabling it completely for a release and then bringing it back later is a reasonable method to implement a behaviour change.