comp.lang.ada
 help / color / mirror / Atom feed
* Positional Aggregates
@ 1998-11-11  0:00 John McCabe
  1998-11-11  0:00 ` dennison
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: John McCabe @ 1998-11-11  0:00 UTC (permalink / raw)


In a declarative part of a subroutine I have lines like the following:

   Files_Used  : constant := 1;
   Files_Index : array (1..Files_Used) of Integer := (17);

When compiled, I get a warning:

   error: positional aggregate cannot have one component

Is this valid for an array with only one element?

-- 
Best Regards
John McCabe
---------------------------------------------------------------------
Marconi Electronic Systems
Simulation & Training Division
=====================================================================
Not necessarily my company or service providers opinions.
=====================================================================






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

* Re: Positional Aggregates
  1998-11-11  0:00 Positional Aggregates John McCabe
  1998-11-11  0:00 ` dennison
  1998-11-11  0:00 ` Marc A. Criley
@ 1998-11-11  0:00 ` John McCabe
  1998-11-12  0:00   ` dewarr
  2 siblings, 1 reply; 9+ messages in thread
From: John McCabe @ 1998-11-11  0:00 UTC (permalink / raw)


John McCabe <john@assen.demon.co.uk> wrote:
>In a declarative part of a subroutine I have lines like the following:
>
>   Files_Used  : constant := 1;
>   Files_Index : array (1..Files_Used) of Integer := (17);
>
>When compiled, I get a warning:
>
>   error: positional aggregate cannot have one component
>
>Is this valid for an array with only one element?
>

I guess I should have looked at this bit of the ARM first!!!!


"NOTES
   (10) In an array_aggregate, positional notation may only be used with
   two or more expressions; a single expression in parentheses is 
   interpreted as a parenthesized_expression. A named_array_aggregate,
   such as (1 => X), may be used to specify an array with a single
   component."

Sorry to have wasted your time.

-- 
Best Regards
John McCabe
---------------------------------------------------------------------
Marconi Electronic Systems
Simulation & Training Division
=====================================================================
Not necessarily my company or service providers opinions.
=====================================================================






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

* Re: Positional Aggregates
  1998-11-11  0:00 Positional Aggregates John McCabe
  1998-11-11  0:00 ` dennison
@ 1998-11-11  0:00 ` Marc A. Criley
  1998-11-11  0:00 ` John McCabe
  2 siblings, 0 replies; 9+ messages in thread
From: Marc A. Criley @ 1998-11-11  0:00 UTC (permalink / raw)


John McCabe wrote:
> 
> In a declarative part of a subroutine I have lines like the following:
> 
>    Files_Used  : constant := 1;
>    Files_Index : array (1..Files_Used) of Integer := (17);
> 
> When compiled, I get a warning:
> 
>    error: positional aggregate cannot have one component

Actually, that's an error :-)

> 
> Is this valid for an array with only one element?

No, the reason is the syntactic ambiguity of a single expression within
parentheses.  The parser can't distinguish between "(17) the single-
element aggregate" and "(17) the number with unnecessary parameters".

The solution to this, in those situations where you're hardcoding the
single element aggregate initializations, is of course:

    Files_Index : array (1..Files_Used) of Integer := (1 => 17);


> --
> Best Regards
> John McCabe
> ---------------------------------------------------------------------
> Marconi Electronic Systems
> Simulation & Training Division
> =====================================================================
> Not necessarily my company or service providers opinions.
> =====================================================================

-- 
Marc A. Criley
Chief Software Architect
Lockheed Martin ATWCS
marc.a.criley@lmco.com
Phone: (610) 354-7861
Fax  : (610) 354-7308




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

* Re: Positional Aggregates
  1998-11-11  0:00 Positional Aggregates John McCabe
@ 1998-11-11  0:00 ` dennison
  1998-11-12  0:00   ` dewar
  1998-11-11  0:00 ` Marc A. Criley
  1998-11-11  0:00 ` John McCabe
  2 siblings, 1 reply; 9+ messages in thread
From: dennison @ 1998-11-11  0:00 UTC (permalink / raw)


In article <72cbru$juh@gcsin3.geccs.gecm.com>,
  John McCabe <john@assen.demon.co.uk> wrote:
> In a declarative part of a subroutine I have lines like the following:
>
>    Files_Used  : constant := 1;
>    Files_Index : array (1..Files_Used) of Integer := (17);
>
> When compiled, I get a warning:
>
>    error: positional aggregate cannot have one component
>
> Is this valid for an array with only one element?

It never worked for me before. Try

    Files_Index : array (1..Files_Used) of Integer := (others => 17);

BTW: That's the best error message for that error I've ever seen.

--
T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Positional Aggregates
  1998-11-11  0:00 ` dennison
@ 1998-11-12  0:00   ` dewar
  1998-11-12  0:00     ` John McCabe
  0 siblings, 1 reply; 9+ messages in thread
From: dewar @ 1998-11-12  0:00 UTC (permalink / raw)


In article <72cq2h$7bd$1@nnrp1.dejanews.com>,
  dennison@telepath.com wrote:
> >    error: positional aggregate cannot have
> >                                          one component
> >
> > Is this valid for an array with only one element?
>
> It never worked for me before. Try
>
>     Files_Index : array (1..Files_Used) of Integer :=
>                                          (others => 17);
>
> BTW: That's the best error message for that error I've
> ever seen.

Thankyou for that nice note! The GNAT circuit for producing
this error message is indeed a little tricky, but we found
it was a common error and thus worth the effort to special
case the error message :-)

Strictly of course (17) simply is not an aggregate at all
but just a parenthesized expression. What GNAT does here is
to specially check for a parenthesized expression of type
foo in a context expecting array-of-foo.


Robert Dewar
Ada Core Technologies



-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Positional Aggregates
  1998-11-11  0:00 ` John McCabe
@ 1998-11-12  0:00   ` dewarr
  1998-11-12  0:00     ` John McCabe
  0 siblings, 1 reply; 9+ messages in thread
From: dewarr @ 1998-11-12  0:00 UTC (permalink / raw)


In article <72cc49$juh@gcsin3.geccs.gecm.com>,
  John McCabe <john@assen.demon.co.uk> wrote:
> John McCabe <john@assen.demon.co.uk> wrote:
> >In a declarative part of a subroutine I have lines like
the following:
> >
> >   Files_Used  : constant := 1;
> >   Files_Index : array (1..Files_Used) of Integer :=
(17);
> >
> >When compiled, I get a warning:
> >
> >   error: positional aggregate cannot have one component
> >
> >Is this valid for an array with only one element?
> >
>
> I guess I should have looked at this bit of the ARM
first!!!!


or you could have just believed the error message :-)

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Positional Aggregates
  1998-11-12  0:00   ` dewar
@ 1998-11-12  0:00     ` John McCabe
  1998-11-12  0:00       ` dewarr
  0 siblings, 1 reply; 9+ messages in thread
From: John McCabe @ 1998-11-12  0:00 UTC (permalink / raw)


dewar@gnat.com wrote:
>In article <72cq2h$7bd$1@nnrp1.dejanews.com>,
>  dennison@telepath.com wrote:

>> BTW: That's the best error message for that error I've
>> ever seen.
>
>Thankyou for that nice note! The GNAT circuit for producing
>this error message is indeed a little tricky, but we found
>it was a common error and thus worth the effort to special
>case the error message :-)

Who said I was using GNAT :-)

-- 
Best Regards
John McCabe
---------------------------------------------------------------------
Marconi Electronic Systems
Simulation & Training Division
=====================================================================
Not necessarily my company or service providers opinions.
=====================================================================






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

* Re: Positional Aggregates
  1998-11-12  0:00   ` dewarr
@ 1998-11-12  0:00     ` John McCabe
  0 siblings, 0 replies; 9+ messages in thread
From: John McCabe @ 1998-11-12  0:00 UTC (permalink / raw)


dewarr@my-dejanews.com wrote:
>In article <72cc49$juh@gcsin3.geccs.gecm.com>,
>  John McCabe <john@assen.demon.co.uk> wrote:
>> John McCabe <john@assen.demon.co.uk> wrote:

>> I guess I should have looked at this bit of the ARM
>first!!!!
>
>
>or you could have just believed the error message :-)

But without your explanation of the parenthesised expression etc etc, it 
just seemed a bit daft.

-- 
Best Regards
John McCabe
---------------------------------------------------------------------
Marconi Electronic Systems
Simulation & Training Division
=====================================================================
Not necessarily my company or service providers opinions.
=====================================================================






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

* Re: Positional Aggregates
  1998-11-12  0:00     ` John McCabe
@ 1998-11-12  0:00       ` dewarr
  0 siblings, 0 replies; 9+ messages in thread
From: dewarr @ 1998-11-12  0:00 UTC (permalink / raw)


In article <72e95b$top@gcsin3.geccs.gecm.com>,
  John McCabe <john@assen.demon.co.uk> wrote:
> dewar@gnat.com wrote:
> >In article <72cq2h$7bd$1@nnrp1.dejanews.com>,
> >  dennison@telepath.com wrote:
>
> >> BTW: That's the best error message for that error I've
> >> ever seen.
> >
> >Thankyou for that nice note! The GNAT circuit for
producing
> >this error message is indeed a little tricky, but we
found
> >it was a common error and thus worth the effort to
special
> >case the error message :-)
>
> Who said I was using GNAT :-)


I assumed you were, since the error message you
quoted was word for word the one that comes out
of GNAT. Of course if some other compiler generates
that message, that's just fine! But the compilers
other than GNAT that we have access to don't
generate nearly such a nice message.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

end of thread, other threads:[~1998-11-12  0:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-11-11  0:00 Positional Aggregates John McCabe
1998-11-11  0:00 ` dennison
1998-11-12  0:00   ` dewar
1998-11-12  0:00     ` John McCabe
1998-11-12  0:00       ` dewarr
1998-11-11  0:00 ` Marc A. Criley
1998-11-11  0:00 ` John McCabe
1998-11-12  0:00   ` dewarr
1998-11-12  0:00     ` John McCabe

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