Re: Array slices and types



On Aug 21, 1:53 am, "Dmitry A. Kazakov" <mail...@xxxxxxxxxxxxxxxxx>
wrote:
On Thu, 21 Aug 2008 08:26:26 +0300, Niklas Holsti wrote:
But doesn't this example show that it would be useful to have 'Base
also for array types?

For any type, actually.

Consider this language design fault:

procedure Initialize (X : in out S) is
begin
Initialize (T (X));
... -- My stuff
end Initialize;

A call to Initialize should be done automatically, but it is not. So the
parent of S must be explicitly specified and known to all descendant. This
is a really *bad* thing:

package Foo is
type S is new T with private;
private
type S is new Private_Decendant_Of_T with ...;
end Foo;

What would happen if Private_Decendant_Of_T overrode Initialize of T? The
result would be an inability to publicly derive from S any new types if
Initialize should be extended!

S'Base could mend it:

procedure Initialize (X : in out S) is
begin
(S"Base (X)).Initialize; -- Call to parent whatever it be
... -- My stuff
end Initialize;

Sorry, Dmitry, but if you'll pardon the expression, you're a little
off-base here. S'Base and S are subtypes of the same *type*. They
may be different subtypes (have different constraints), but they're
the same type. You're asking for an attribute that would give you a
different type. There may be merit in having such an attribute (I
haven't looked into it closely), but calling it 'Base would be a bad
idea. S'Parent might be better.

Niklas is asking for S'Base to be the unconstrained array subtype of
the (possibly constrained) array subtype S. It would still fit into
the definition of 'Base (3.5(15)). I'm not sure why this wasn't
defined for array subtypes, or for any other type that could have
discriminants; offhand I don't see how this would cause any problems.

-- Adam

.



Relevant Pages

  • Re: compiler bugs
    ... In a language like C, the behavior of programs that reference ... Not if the unoptimizing compiler initializes all variables to some ... portion of the array in your algorithhm. ... that one actually does not need to initialize all variables (unlike ...
    (comp.compilers)
  • Re: Error 216 (related to SetLength)
    ... It might turn out that you're writing to a part of an array that doesn't exist. ... suggests you're talking about an access violation (in which case I'd like to know what addresses the exception reports), but your previous message only quoted the text from a different kind of exception, about changing visibility in OnShow or OnHide. ... I'd even go so far as to argue that OnCreate isn't the right place, ... Since your variables are global, they aren't related to any specific form, so a form isn't what should initialize them. ...
    (alt.comp.lang.borland-delphi)
  • Re: compiler bugs
    ... While I hate disagreeing with you Anton, ... Not if the unoptimizing compiler initializes all variables to some ... portion of the array in your algorithhm. ... being able to not actually initialize the array for the unused ...
    (comp.compilers)
  • Re: behavior-preserving optimization in C, was compiler bugs
    ... initialization is the same with and without optimization. ... initialize to a defined value that also survives, e.g., program ... by zero is in a function that references an uninitialized local array ... changes to register and stack ...
    (comp.compilers)
  • Re: Function lookup tables?
    ... Ignore any typos the source is good except howto initialize the function ... > I want to initialize the function lookup table array to my member ... > function calls of the class inside of the constructor for the class. ... > What is the correct code to initialize the function pointer array ...
    (comp.lang.cpp)