Menu

#774 Weird feature of 2 syntaxes for declaring/defining dynamic arrays which allow use of initializer '= ANY'

open
nobody
None
compiler
2025-08-09
2015-04-28
No

I would highlight a weird feature of these syntaxes (for declaring/defining dynamic arrays) which allow to use also the initializer '= ANY':

[Re]Dim [Shared] As datatype symbolName() = ANY
In that declaring syntax, the initializer '= ANY' is allowed although it is irrelevant!

Redim [Shared] As datatype symbolName([subscript [, ...]]) = ANY
In that defining syntax, the initializer '= ANY' is allowed, nevertheless the constructor is still called!

Referring at forum to the post:
http://www.freebasic.net/forum/viewtopic.php?p=207298#p207298

Discussion

  • dkl

    dkl - 2015-06-06

    The way I understand it now is:

    • An ANY initializer can be specified for dynamic array vars/fields/params, but not on (subsequent) redims
    • it disables the initialization of array elements (not of the descriptor)
    • but it's a bit broken currently, because it only disables clearing, not constructor calls

    The problem with the last point is that the current rtlib functions for redimming arrays of objects don't have parameters for disabling the clearing like the "normal" (non-object) array redimming functions. So to fix that, we have to add new rtlib functions with new names, to avoid breaking the ABI. A lot of trouble for small gain...

     
  • fxm (freebasic.net)

    I started the topic "Validity/Behavior of 'ANY' initializer versus datatypes with default constructor":
    https://www.freebasic.net/forum/viewtopic.php?t=33278
    to discuss and decide on the usage and behavior of 'Any' versus objects with constructors.
    Currently, the behavior of 'Any' varies greatly, depending on the data type and declaration type.
    Therefore, processing of this bug report is suspended for the time being.

     

Log in to post a comment.

MongoDB Logo MongoDB