Recent

Author Topic: Default intrinsic and subrange types.  (Read 294 times)

avk

  • Hero Member
  • *****
  • Posts: 602
    • my self-education project
Default intrinsic and subrange types.
« on: May 29, 2022, 02:41:30 pm »
According to the current documentation:
Quote
Default is a compiler intrinsic: it returns for every type T a default value. In essence, this is a block of memory that is zeroed out. It can be used to correctly initialize any type, and more importantly, a managed type. It also works using a generic type template.

This function cannot be used on any of the file types or complex types that contain a file type.

For subranges of the form 42..1001, the Default() function returns a value that does not belong to this type (this is 0, of course).
Should this be seen as a gap in the documentation, or can the situation be fixed somehow?

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 970
Re: Default intrinsic and subrange types.
« Reply #1 on: May 29, 2022, 02:45:56 pm »
A global variable of a subrange type is also initialised with 0, even though that is not a valid value for such a variable.

In the general sense, it is impossible to define Default in a way that always results in a valid value for all variables, because it can also be used for variant records and then you can have overlapping fields of different types and an impossible situation to pick a value that's in the range of all of these types.

So you cannot rely on Default assigning a value that's in range. Since initialising is not the same as assigning a value that's in range, the documentation is correct.

avk

  • Hero Member
  • *****
  • Posts: 602
    • my self-education project
Re: Default intrinsic and subrange types.
« Reply #2 on: May 29, 2022, 03:22:36 pm »
Thank you.

 

TinyPortal © 2005-2018