comp.lang.ada
 help / color / mirror / Atom feed
* Generic Zero Length Array
@ 2008-02-22 13:31 shaunpatterson
  2008-02-22 13:53 ` Egil Høvik
                   ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: shaunpatterson @ 2008-02-22 13:31 UTC (permalink / raw)


I have a bit of legacy code in my system that I am trying to remove
all warnings from.

The package is a generic -- with:

type Element is (<>);
type Element_List is array (Indexing range <>) of Element;


I have been stumped by one compiler warning where one of the functions
needs to return a zero-length empty generic array:

warning: variable Result_String is read but never assigned

code:

if Error_Condition then
  declare
    type Result is new Element_List (Indexing.First + 1 ..
Indexing'First);
    Result_String : Result;
  begin
     return Element_List (Result);
  end;
end if;

How do I initialize this array when I can't know what type it is or
will be?

Thanks

--
Shaun




^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-22 13:31 Generic Zero Length Array shaunpatterson
@ 2008-02-22 13:53 ` Egil Høvik
  2008-02-22 13:55   ` shaunpatterson
                     ` (3 more replies)
  2008-02-22 14:23 ` Stefan Lucks
                   ` (2 subsequent siblings)
  3 siblings, 4 replies; 19+ messages in thread
From: Egil Høvik @ 2008-02-22 13:53 UTC (permalink / raw)


On Feb 22, 2:31 pm, shaunpatter...@gmail.com wrote:
> I have a bit of legacy code in my system that I am trying to remove
> all warnings from.
>
> The package is a generic -- with:
>
> type Element is (<>);
> type Element_List is array (Indexing range <>) of Element;
>
> I have been stumped by one compiler warning where one of the functions
> needs to return a zero-length empty generic array:
>
> warning: variable Result_String is read but never assigned
>
> code:
>
> if Error_Condition then
>   declare
>     type Result is new Element_List (Indexing.First + 1 ..
> Indexing'First);
>     Result_String : Result;
>   begin
>      return Element_List (Result);
>   end;
> end if;
>
> How do I initialize this array when I can't know what type it is or
> will be?
>
> Thanks
>
> --
> Shaun


A new generic parameter Null_Element would do the trick, but
that means changing code wherever the generic is used...

type Element is (<>);
type Element_List is array (Indexing range <>) of Element;
Null_Element : Element;


then you could rewrite the above code to

if Error_Condition then
  return Element_List'(Indexing'First..Indexing'First-1 =>
Null_Element);
end if;


--
~egilhh



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-22 13:53 ` Egil Høvik
@ 2008-02-22 13:55   ` shaunpatterson
  2008-02-22 14:11     ` Georg Bauhaus
  2008-02-22 19:25   ` Randy Brukardt
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 19+ messages in thread
From: shaunpatterson @ 2008-02-22 13:55 UTC (permalink / raw)


Yes, I was afraid that would be my only option.

Thank you.

--
Shaun




^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-22 13:55   ` shaunpatterson
@ 2008-02-22 14:11     ` Georg Bauhaus
  0 siblings, 0 replies; 19+ messages in thread
From: Georg Bauhaus @ 2008-02-22 14:11 UTC (permalink / raw)


shaunpatterson@gmail.com wrote:
> Yes, I was afraid that would be my only option.
> 

Wait, when generic formal type Element has Element'First,
you can use it in

   return Element_List'
     (Indexing.First + 1 .. Indexing'First => Element'First);

etc.

 -- Georg



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-22 13:31 Generic Zero Length Array shaunpatterson
  2008-02-22 13:53 ` Egil Høvik
@ 2008-02-22 14:23 ` Stefan Lucks
  2008-02-22 16:52   ` Adam Beneschan
  2008-02-22 14:26 ` Robert A Duff
  2008-02-22 15:22 ` Stefan Bellon
  3 siblings, 1 reply; 19+ messages in thread
From: Stefan Lucks @ 2008-02-22 14:23 UTC (permalink / raw)



On Fri, 22 Feb 2008, shaunpatterson@gmail.com wrote:

> How do I initialize this array when I can't know what type it is or
> will be?

> if Error_Condition then
>  declare
>    type Result is new Element_List (Indexing.First + 1 ..
> Indexing'First);
>    Result_String : Result;

     Result_String : Result := (others => Some_Default_Value);

>  begin
>     return Element_List (Result);
>  end;
> end if;



This should work. The default value doesn't matter at all, because the 
array is empty. But you still need to know a default value of the 
appropriate type.


BTW, why do you declare the type "Result" at all? The following should 
work as well:

   if ... then
      declare
         Result_String: Element_List(Indexing'First+1 .. Indexing'First)
           := (others => Some_Default_Value);
      begin
         return Result_String;
      end;
   end if;





-- 
Stefan Lucks      (moved to Bauhaus-University Weimar, Germany)
 		       <Stefan.Lucks at medien.uni-weimar.de>
------  I  love  the  taste  of  Cryptanalysis  in  the  morning!  ------





^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-22 13:31 Generic Zero Length Array shaunpatterson
  2008-02-22 13:53 ` Egil Høvik
  2008-02-22 14:23 ` Stefan Lucks
@ 2008-02-22 14:26 ` Robert A Duff
  2008-02-22 15:22 ` Stefan Bellon
  3 siblings, 0 replies; 19+ messages in thread
From: Robert A Duff @ 2008-02-22 14:26 UTC (permalink / raw)


shaunpatterson@gmail.com writes:

> I have a bit of legacy code in my system that I am trying to remove
> all warnings from.
>
> The package is a generic -- with:
>
> type Element is (<>);
> type Element_List is array (Indexing range <>) of Element;
>
>
> I have been stumped by one compiler warning where one of the functions
> needs to return a zero-length empty generic array:
>
> warning: variable Result_String is read but never assigned

If the warning is wrong, the appropriate thing to do is
pragma Warnings(Off, ...).  See the docs for various useful
options.  Also look at pragma Unreferenced, which might be
appropriate in other cases.

> code:
>
> if Error_Condition then
>   declare
>     type Result is new Element_List (Indexing.First + 1 ..
> Indexing'First);
>     Result_String : Result;
>   begin
>      return Element_List (Result);
>   end;
> end if;

You've got some typos there -- better to cut&paste the exact code.

I can't tell for sure without more context, but that code looks strange.
Why declare a new type?  Why not:

    subtype Result is Element_List (...);
    Result_String : Result;
    ...
    return Result_String;

Or:

    Result_String : Element_List (...);
    ...
    return Result_String;

Or (in Ada 2005):

    return Element_List'(Indexing'Base'First+1 .. Indexing'Base'First => <>);

And it wouldn't hurt to put:

    pragma Assert (Indexing'Base'First < Indexing'Base'Last);

in the package spec, since this generic won't work with
a one-element or zero-element base type.

> How do I initialize this array when I can't know what type it is or
> will be?

You don't have to initialize it.  But if you want to, an aggregate will
work.

- Bob



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-22 13:31 Generic Zero Length Array shaunpatterson
                   ` (2 preceding siblings ...)
  2008-02-22 14:26 ` Robert A Duff
@ 2008-02-22 15:22 ` Stefan Bellon
  2008-02-22 23:03   ` Adam Beneschan
  3 siblings, 1 reply; 19+ messages in thread
From: Stefan Bellon @ 2008-02-22 15:22 UTC (permalink / raw)


On Fr, 22 Feb, shaunpatterson@gmail.com wrote:

> if Error_Condition then
>   declare
>     type Result is new Element_List (Indexing.First + 1 ..
> Indexing'First);
>     Result_String : Result;
>   begin
>      return Element_List (Result);
>   end;
> end if;
> 
> How do I initialize this array when I can't know what type it is or
> will be?

Funny, just yesterday I came across the code that did exactly this
in our software:

   if List_Length = 0 then
      if Index_Type'Base'First = Index_Type'Base'Last then
         --  there seems to be no way to declare a null array
         --  for a `type Index_Type is (A)`
         raise Constraint_Error;
      else
         --  Workaround due to GNAT 6.0.2 bug (H221-018).
         return (Index_Type'Base'Last ..
                 Index_Type'Base'Pred (Index_Type'Base'Last) => <>);
      end if;
   else
      --  non-empty case
   end if;

And previously we had

         return (Index_Type'Base'Last .. Index_Type'Base'First => <>);

written, which triggered H221-018, therefore we rewrote to use 'Pred.

Greetings,
Stefan

-- 
Stefan Bellon



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-22 14:23 ` Stefan Lucks
@ 2008-02-22 16:52   ` Adam Beneschan
  0 siblings, 0 replies; 19+ messages in thread
From: Adam Beneschan @ 2008-02-22 16:52 UTC (permalink / raw)


On Feb 22, 6:23 am, Stefan Lucks <lu...@th.informatik.uni-mannheim.de>
wrote:
> On Fri, 22 Feb 2008, shaunpatter...@gmail.com wrote:
> > How do I initialize this array when I can't know what type it is or
> > will be?
> > if Error_Condition then
> >  declare
> >    type Result is new Element_List (Indexing.First + 1 ..
> > Indexing'First);
> >    Result_String : Result;
>
>      Result_String : Result := (others => Some_Default_Value);
>
> >  begin
> >     return Element_List (Result);
> >  end;
> > end if;
>
> This should work. The default value doesn't matter at all, because the
> array is empty. But you still need to know a default value of the
> appropriate type.

If the *only* use of this default value would be to use it as an
initializer for an array that we know is going to be empty, so that
the default value is never used, I don't think I'd recommend this
solution.  It may work to get rid of the warnings, but it seems like a
poor design idea to require a parameter that is never used.

I think one of Bob's solutions is preferable, if it's really necessary
to get rid of the warnings.  This is simply a case where you know more
than the compiler.

However, in a case where you do need to initialize something of a
generic formal type, adding an "initial value" generic parameter is
the way to do it.

                                    -- Adam



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-22 13:53 ` Egil Høvik
  2008-02-22 13:55   ` shaunpatterson
  2008-02-22 19:25   ` Randy Brukardt
@ 2008-02-22 19:25   ` Randy Brukardt
  2008-02-22 19:25   ` Randy Brukardt
  3 siblings, 0 replies; 19+ messages in thread
From: Randy Brukardt @ 2008-02-22 19:25 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1185 bytes --]

"Egil H�vik" <egilhovik@hotmail.com> wrote in message
news:2446841a-8bb0-46bc-94ed-099e4e0ca74c@k2g2000hse.googlegroups.com...
>On Feb 22, 2:31 pm, shaunpatter...@gmail.com wrote:
>> I have a bit of legacy code in my system that I am trying to remove
>> all warnings from.
>>
>> The package is a generic -- with:
>>
>> type Element is (<>);
>> type Element_List is array (Indexing range <>) of Element;
>>
>> I have been stumped by one compiler warning where one of the functions
>> needs to return a zero-length empty generic array:
...
>A new generic parameter Null_Element would do the trick, but
>that means changing code wherever the generic is used...
>
>type Element is (<>);
>type Element_List is array (Indexing range <>) of Element;
>Null_Element : Element;
>
>then you could rewrite the above code to
>
>if Error_Condition then
>  return Element_List'(Indexing'First..Indexing'First-1 => Null_Element);
>end if;

If you are not limited to Ada 95, you can use the <> here, and then you
don't need the extra generic parameter:

if Error_Condition then
  return Element_List'(Indexing'First..Indexing'First-1 => <>);
end if;

                           Randy.
--
~egilhh





^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-22 13:53 ` Egil Høvik
                     ` (2 preceding siblings ...)
  2008-02-22 19:25   ` Randy Brukardt
@ 2008-02-22 19:25   ` Randy Brukardt
  3 siblings, 0 replies; 19+ messages in thread
From: Randy Brukardt @ 2008-02-22 19:25 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1185 bytes --]

"Egil H�vik" <egilhovik@hotmail.com> wrote in message
news:2446841a-8bb0-46bc-94ed-099e4e0ca74c@k2g2000hse.googlegroups.com...
>On Feb 22, 2:31 pm, shaunpatter...@gmail.com wrote:
>> I have a bit of legacy code in my system that I am trying to remove
>> all warnings from.
>>
>> The package is a generic -- with:
>>
>> type Element is (<>);
>> type Element_List is array (Indexing range <>) of Element;
>>
>> I have been stumped by one compiler warning where one of the functions
>> needs to return a zero-length empty generic array:
...
>A new generic parameter Null_Element would do the trick, but
>that means changing code wherever the generic is used...
>
>type Element is (<>);
>type Element_List is array (Indexing range <>) of Element;
>Null_Element : Element;
>
>then you could rewrite the above code to
>
>if Error_Condition then
>  return Element_List'(Indexing'First..Indexing'First-1 => Null_Element);
>end if;

If you are not limited to Ada 95, you can use the <> here, and then you
don't need the extra generic parameter:

if Error_Condition then
  return Element_List'(Indexing'First..Indexing'First-1 => <>);
end if;

                           Randy.
--
~egilhh





^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-22 13:53 ` Egil Høvik
  2008-02-22 13:55   ` shaunpatterson
@ 2008-02-22 19:25   ` Randy Brukardt
  2008-02-22 23:01     ` Adam Beneschan
  2008-02-22 19:25   ` Randy Brukardt
  2008-02-22 19:25   ` Randy Brukardt
  3 siblings, 1 reply; 19+ messages in thread
From: Randy Brukardt @ 2008-02-22 19:25 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1185 bytes --]

"Egil H�vik" <egilhovik@hotmail.com> wrote in message
news:2446841a-8bb0-46bc-94ed-099e4e0ca74c@k2g2000hse.googlegroups.com...
>On Feb 22, 2:31 pm, shaunpatter...@gmail.com wrote:
>> I have a bit of legacy code in my system that I am trying to remove
>> all warnings from.
>>
>> The package is a generic -- with:
>>
>> type Element is (<>);
>> type Element_List is array (Indexing range <>) of Element;
>>
>> I have been stumped by one compiler warning where one of the functions
>> needs to return a zero-length empty generic array:
...
>A new generic parameter Null_Element would do the trick, but
>that means changing code wherever the generic is used...
>
>type Element is (<>);
>type Element_List is array (Indexing range <>) of Element;
>Null_Element : Element;
>
>then you could rewrite the above code to
>
>if Error_Condition then
>  return Element_List'(Indexing'First..Indexing'First-1 => Null_Element);
>end if;

If you are not limited to Ada 95, you can use the <> here, and then you
don't need the extra generic parameter:

if Error_Condition then
  return Element_List'(Indexing'First..Indexing'First-1 => <>);
end if;

                           Randy.
--
~egilhh





^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-22 19:25   ` Randy Brukardt
@ 2008-02-22 23:01     ` Adam Beneschan
  2008-02-23  9:30       ` Dmitry A. Kazakov
  2008-02-23 14:27       ` Robert A Duff
  0 siblings, 2 replies; 19+ messages in thread
From: Adam Beneschan @ 2008-02-22 23:01 UTC (permalink / raw)


On Feb 22, 11:25 am, "Randy Brukardt" <ra...@rrsoftware.com> wrote:
> "Egil Høvik" <egilho...@hotmail.com> wrote in message
>
> news:2446841a-8bb0-46bc-94ed-099e4e0ca74c@k2g2000hse.googlegroups.com...
>
>
>
> >On Feb 22, 2:31 pm, shaunpatter...@gmail.com wrote:
> >> I have a bit of legacy code in my system that I am trying to remove
> >> all warnings from.
>
> >> The package is a generic -- with:
>
> >> type Element is (<>);
> >> type Element_List is array (Indexing range <>) of Element;
>
> >> I have been stumped by one compiler warning where one of the functions
> >> needs to return a zero-length empty generic array:
> ...
> >A new generic parameter Null_Element would do the trick, but
> >that means changing code wherever the generic is used...
>
> >type Element is (<>);
> >type Element_List is array (Indexing range <>) of Element;
> >Null_Element : Element;
>
> >then you could rewrite the above code to
>
> >if Error_Condition then
> >  return Element_List'(Indexing'First..Indexing'First-1 => Null_Element);
> >end if;
>
> If you are not limited to Ada 95, you can use the <> here, and then you
> don't need the extra generic parameter:
>
> if Error_Condition then
>   return Element_List'(Indexing'First..Indexing'First-1 => <>);
> end if;

Drat, I wish I'd thought of that.  Yes, this seems best.

Way back before Ada 95, someone made a proposed language array to add
a "null array" aggregate to the language, so that you could write an
aggregate to represent a zero-element array without needing a fake
value for the elements.  I thought this was a great idea and could
never understand why it wasn't adopted.  It would have solved the
problem here.  But the <> syntax of Ada 2005 obviates the need for
something like that.  I don't think we need "null record" (i.e. in
aggregates) any more either, although certainly nobody is going to
suggest removing it.

[Actually, there's one case where you still can't specify a null array
aggregate, and that's where the index type is either "mod 1" or an
enumeration type with one value:

         type Enum is (This_One);
         type Arr is array (Enum range <>) of Anything;

Now go ahead and try to specify a zero-element array aggregate of type
Arr.  You can't.  But this is a pretty pathological case so it's not
worth trying to change the language for it.]

                                  -- Adam




^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-22 15:22 ` Stefan Bellon
@ 2008-02-22 23:03   ` Adam Beneschan
  2008-02-23 10:19     ` Stefan Bellon
  0 siblings, 1 reply; 19+ messages in thread
From: Adam Beneschan @ 2008-02-22 23:03 UTC (permalink / raw)


On Feb 22, 7:22 am, Stefan Bellon <bel...@software-erosion.org> wrote:

> And previously we had
>
>          return (Index_Type'Base'Last .. Index_Type'Base'First => <>);
>
> written, which triggered H221-018, therefore we rewrote to use 'Pred.

OK, what's H221-018?  I hope it's nothing like O157:H7...

                                    -- Adam




^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-22 23:01     ` Adam Beneschan
@ 2008-02-23  9:30       ` Dmitry A. Kazakov
  2008-02-23 14:27       ` Robert A Duff
  1 sibling, 0 replies; 19+ messages in thread
From: Dmitry A. Kazakov @ 2008-02-23  9:30 UTC (permalink / raw)


On Fri, 22 Feb 2008 15:01:02 -0800 (PST), Adam Beneschan wrote:

> [Actually, there's one case where you still can't specify a null array
> aggregate, and that's where the index type is either "mod 1" or an
> enumeration type with one value:
> 
>          type Enum is (This_One);
>          type Arr is array (Enum range <>) of Anything;
> 
> Now go ahead and try to specify a zero-element array aggregate of type
> Arr.  You can't.  But this is a pretty pathological case so it's not
> worth trying to change the language for it.]

I think it would, because the problem is that a null range cannot
specified. And more generally is that ranges aren't first-class citizens.
The language would be better if that were fixed.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-22 23:03   ` Adam Beneschan
@ 2008-02-23 10:19     ` Stefan Bellon
  0 siblings, 0 replies; 19+ messages in thread
From: Stefan Bellon @ 2008-02-23 10:19 UTC (permalink / raw)


On Fr, 22 Feb, Adam Beneschan wrote:

> On Feb 22, 7:22 am, Stefan Bellon <bel...@software-erosion.org> wrote:
> 
> > And previously we had
> >
> >          return (Index_Type'Base'Last .. Index_Type'Base'First =>
> > <>);
> >
> > written, which triggered H221-018, therefore we rewrote to use
> > 'Pred.
> 
> OK, what's H221-018?  I hope it's nothing like O157:H7...

I don't know of 0157:H7, but H221-018 is AdaCore's tracker issue ID
under which I filed the problem. We annotate workarounds in the source
code with those IDs, so we can go through the code and remove the
workarounds as soon as they are fixed in a new release. Sorry if that
caused confusion, perhaps I should have removed the comment before
posting. :-}

-- 
Stefan Bellon



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-22 23:01     ` Adam Beneschan
  2008-02-23  9:30       ` Dmitry A. Kazakov
@ 2008-02-23 14:27       ` Robert A Duff
  2008-02-23 16:16         ` Dmitry A. Kazakov
  2008-02-25 16:41         ` Adam Beneschan
  1 sibling, 2 replies; 19+ messages in thread
From: Robert A Duff @ 2008-02-23 14:27 UTC (permalink / raw)


Adam Beneschan <adam@irvine.com> writes:

> Way back before Ada 95, someone made a proposed language array to add
> a "null array" aggregate to the language, so that you could write an
> aggregate to represent a zero-element array without needing a fake
> value for the elements.  I thought this was a great idea and could
> never understand why it wasn't adopted.  It would have solved the
> problem here.  But the <> syntax of Ada 2005 obviates the need for
> something like that.

I still think it's a language design flaw that you can't write a
zero-element or one-element positional aggregate.

>...I don't think we need "null record" (i.e. in
> aggregates) any more either, although certainly nobody is going to
> suggest removing it.

Why don't we need that?

> [Actually, there's one case where you still can't specify a null array
> aggregate, and that's where the index type is either "mod 1" or an
> enumeration type with one value:
>
>          type Enum is (This_One);
>          type Arr is array (Enum range <>) of Anything;
>
> Now go ahead and try to specify a zero-element array aggregate of type
> Arr.  You can't.

Right.  Not just aggregates -- you can't create any zero-element array
of type Arr.

>...But this is a pretty pathological case so it's not
> worth trying to change the language for it.]

If it were worth it, what would be the best change?
I suppose ranges could be characterized by 'First/'Length,
instead of 'First/'Last.  And eliminate 'Last from the language.
Or else say 'Last raises Constraint_Error if 'First = 'Base'First
and 'Length = 0.

- Bob



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-23 14:27       ` Robert A Duff
@ 2008-02-23 16:16         ` Dmitry A. Kazakov
  2008-02-25 16:41         ` Adam Beneschan
  1 sibling, 0 replies; 19+ messages in thread
From: Dmitry A. Kazakov @ 2008-02-23 16:16 UTC (permalink / raw)


On Sat, 23 Feb 2008 09:27:26 -0500, Robert A Duff wrote:

> I suppose ranges could be characterized by 'First/'Length,
> instead of 'First/'Last.  And eliminate 'Last from the language.

Is Index'First any better than Index'Last? Null range does not have any
indices in it. That includes Index'First. Otherwise each element of Index
would have an individual null range associated with it.

(I think there should be something like null of Universal_Range.)

> Or else say 'Last raises Constraint_Error if 'First = 'Base'First
> and 'Length = 0.

A'Range /= A'First..A'Last?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-23 14:27       ` Robert A Duff
  2008-02-23 16:16         ` Dmitry A. Kazakov
@ 2008-02-25 16:41         ` Adam Beneschan
  2008-02-25 19:14           ` Robert A Duff
  1 sibling, 1 reply; 19+ messages in thread
From: Adam Beneschan @ 2008-02-25 16:41 UTC (permalink / raw)


On Feb 23, 6:27 am, Robert A Duff <bobd...@shell01.TheWorld.com>
wrote:
>
> >...I don't think we need "null record" (i.e. in
> > aggregates) any more either, although certainly nobody is going to
> > suggest removing it.
>
> Why don't we need that?

Because if Rec_Type is a record with no components, Rec_Type'(others
=> <>) will work (and has the same effect as (null record)).

Or is there some more complex cases where the "null record" syntax is
still needed in aggregates?

                                    -- Adam



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Generic Zero Length Array
  2008-02-25 16:41         ` Adam Beneschan
@ 2008-02-25 19:14           ` Robert A Duff
  0 siblings, 0 replies; 19+ messages in thread
From: Robert A Duff @ 2008-02-25 19:14 UTC (permalink / raw)


Adam Beneschan <adam@irvine.com> writes:

> On Feb 23, 6:27 am, Robert A Duff <bobd...@shell01.TheWorld.com>
> wrote:
>>
>> >...I don't think we need "null record" (i.e. in
>> > aggregates) any more either, although certainly nobody is going to
>> > suggest removing it.
>>
>> Why don't we need that?
>
> Because if Rec_Type is a record with no components, Rec_Type'(others
> => <>) will work (and has the same effect as (null record)).

Ah, I see what you mean.

I still want "null record", because it means something different from
"others".  The "null record" means I assert that there are no
components, and please slap me with a compile-time error if
that's not true (or no longer true).  The "others" means that
I want all components to be default-initialized, including
all the ones that have not yet been invented.

If somebody changes "type T is null record" to
"type T is record Blah : Integer; end record;"
I want an error on all the (null record) aggregates.

> Or is there some more complex cases where the "null record" syntax is
> still needed in aggregates?

No.

- Bob



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2008-02-25 19:14 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-22 13:31 Generic Zero Length Array shaunpatterson
2008-02-22 13:53 ` Egil Høvik
2008-02-22 13:55   ` shaunpatterson
2008-02-22 14:11     ` Georg Bauhaus
2008-02-22 19:25   ` Randy Brukardt
2008-02-22 23:01     ` Adam Beneschan
2008-02-23  9:30       ` Dmitry A. Kazakov
2008-02-23 14:27       ` Robert A Duff
2008-02-23 16:16         ` Dmitry A. Kazakov
2008-02-25 16:41         ` Adam Beneschan
2008-02-25 19:14           ` Robert A Duff
2008-02-22 19:25   ` Randy Brukardt
2008-02-22 19:25   ` Randy Brukardt
2008-02-22 14:23 ` Stefan Lucks
2008-02-22 16:52   ` Adam Beneschan
2008-02-22 14:26 ` Robert A Duff
2008-02-22 15:22 ` Stefan Bellon
2008-02-22 23:03   ` Adam Beneschan
2008-02-23 10:19     ` Stefan Bellon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox