* Anonymous array not allowed as components
@ 2019-11-01 8:32 L Dries
2019-11-01 9:34 ` joakimds
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: L Dries @ 2019-11-01 8:32 UTC (permalink / raw)
I have an need for an array of Unbounded_Strings in which i define the
elements.
I declared it as:
Debug_Proc : array (1 .. nr_Proc) of Unbounded_String :=
(Debug_Proc(Lan),
To_Unbounded_String("Only"),
To_Unbounded_String("Empty_Buffer"),
...
etc.
Then I got the message:
65:22 Anonymous array not allowed as components
This results i a position just before "array"
The value nr_Proc is defined in another package.
Debug_Proc(Lan) is an Unbounded String
I tried to replace nr_Proc by a value. The same result.
I tried to replave the value of the first Unbounded String by "--",
again no result
I tried set it as an constant array, also no result.
What do I do wrong?
--
L. Dries
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Anonymous array not allowed as components
2019-11-01 8:32 Anonymous array not allowed as components L Dries
@ 2019-11-01 9:34 ` joakimds
2019-11-01 10:00 ` L Dries
2019-11-01 10:47 ` Jeffrey R. Carter
2019-11-01 9:34 ` AdaMagica
2019-11-01 10:41 ` Jeffrey R. Carter
2 siblings, 2 replies; 9+ messages in thread
From: joakimds @ 2019-11-01 9:34 UTC (permalink / raw)
Den fredag 1 november 2019 kl. 09:32:42 UTC+1 skrev L Dries:
> I have an need for an array of Unbounded_Strings in which i define the
> elements.
>
> I declared it as:
>
> Debug_Proc : array (1 .. nr_Proc) of Unbounded_String :=
> (Debug_Proc(Lan),
> To_Unbounded_String("Only"),
> To_Unbounded_String("Empty_Buffer"),
> ...
> etc.
>
> Then I got the message:
>
> 65:22 Anonymous array not allowed as components
> This results i a position just before "array"
>
> The value nr_Proc is defined in another package.
> Debug_Proc(Lan) is an Unbounded String
> I tried to replace nr_Proc by a value. The same result.
> I tried to replave the value of the first Unbounded String by "--",
> again no result
> I tried set it as an constant array, also no result.
>
> What do I do wrong?
> --
> L. Dries
Hello L. Dries,
Unbounded_String is well-known for being "slow" because it does unnecessary heap-allocations. To avoid performance penalty the XString type has been defined in the GNATColl library. The point is that one should have very good reasons to use Unbound_String in one's application and not use it needlessly.
In your case what you want is to map each integer in an interval to a specific String. If that's the case I recommend taking advantage of expression functions and case statements introduced in Ada 2012:
type Index is new Integer range 1 .. nr_Proc;
function Debug_Proc (I : Index) return String is
(case I is
when 1 => "Only",
when 2 => "Empty_Buffer", ...);
or maybe it is:
function Debug_Proc (I : Index) return String is
((case I is
when 1 => "Only",
when 2 => "Empty_Buffer", ...));
The compiler will tell you.
Best regards,
Joakim
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Anonymous array not allowed as components
2019-11-01 8:32 Anonymous array not allowed as components L Dries
2019-11-01 9:34 ` joakimds
@ 2019-11-01 9:34 ` AdaMagica
2019-11-01 9:56 ` L Dries
2019-11-01 10:33 ` L Dries
2019-11-01 10:41 ` Jeffrey R. Carter
2 siblings, 2 replies; 9+ messages in thread
From: AdaMagica @ 2019-11-01 9:34 UTC (permalink / raw)
Am Freitag, 1. November 2019 09:32:42 UTC+1 schrieb L Dries:
> I have an need for an array of Unbounded_Strings in which i define the
> elements.
>
> I declared it as:
>
type Container is record
...
> Debug_Proc : array (1 .. nr_Proc) of Unbounded_String :=
> (Debug_Proc(Lan),
> To_Unbounded_String("Only"),
> To_Unbounded_String("Empty_Buffer"),
> ...
> etc.
end record;
>
> Then I got the message:
>
> 65:22 Anonymous array not allowed as components
> This results i a position just before "array"
Reading the compiler message, I get the impression that your Debug_Prog is a component of another record. Just define a matching type and use an object of this type as component.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Anonymous array not allowed as components
2019-11-01 9:34 ` AdaMagica
@ 2019-11-01 9:56 ` L Dries
2019-11-01 10:33 ` L Dries
1 sibling, 0 replies; 9+ messages in thread
From: L Dries @ 2019-11-01 9:56 UTC (permalink / raw)
To: AdaMagica
Op 1-11-2019 om 10:34 schreef AdaMagica:
> ...
I found 1 failure in the code
Debug_Proc(Lan) must be Debug_NoProc(Lan)
but that does not solve the problem.
I just saw some information that i was not aware of:
It looks like the builder is creating the failure
--
L. Dries
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Anonymous array not allowed as components
2019-11-01 9:34 ` joakimds
@ 2019-11-01 10:00 ` L Dries
2019-11-01 10:47 ` Jeffrey R. Carter
1 sibling, 0 replies; 9+ messages in thread
From: L Dries @ 2019-11-01 10:00 UTC (permalink / raw)
To: joakimds
Op 1-11-2019 om 10:34 schreef joakimds@kth.se:
> Den fredag 1 november 2019 kl. 09:32:42 UTC+1 skrev L Dries:
>> I have an need for an array of Unbounded_Strings in which i define the
>> elements.
>>
>> I declared it as:
>>
>> Debug_Proc : array (1 .. nr_Proc) of Unbounded_String :=
>> (Debug_Proc(Lan),
>> To_Unbounded_String("Only"),
>> To_Unbounded_String("Empty_Buffer"),
>> ...
>> etc.
>>
>> Then I got the message:
>>
>> 65:22 Anonymous array not allowed as components
>> This results i a position just before "array"
>>
>> The value nr_Proc is defined in another package.
>> Debug_Proc(Lan) is an Unbounded String
>> I tried to replace nr_Proc by a value. The same result.
>> I tried to replave the value of the first Unbounded String by "--",
>> again no result
>> I tried set it as an constant array, also no result.
>>
>> What do I do wrong?
>> --
>> L. Dries
>
> Hello L. Dries,
>
> Unbounded_String is well-known for being "slow" because it does unnecessary heap-allocations. To avoid performance penalty the XString type has been defined in the GNATColl library. The point is that one should have very good reasons to use Unbound_String in one's application and not use it needlessly.
>
> In your case what you want is to map each integer in an interval to a specific String. If that's the case I recommend taking advantage of expression functions and case statements introduced in Ada 2012:
>
> type Index is new Integer range 1 .. nr_Proc;
>
> function Debug_Proc (I : Index) return String is
> (case I is
> when 1 => "Only",
> when 2 => "Empty_Buffer", ...);
>
> or maybe it is:
>
> function Debug_Proc (I : Index) return String is
> ((case I is
> when 1 => "Only",
> when 2 => "Empty_Buffer", ...));
>
> The compiler will tell you.
>
> Best regards,
> Joakim
>
I will look nto that possibility, but for this project it is too late
because changing would mean almost completely rewriting the program.
--
L. Dries
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Anonymous array not allowed as components
2019-11-01 9:34 ` AdaMagica
2019-11-01 9:56 ` L Dries
@ 2019-11-01 10:33 ` L Dries
2019-11-01 15:55 ` AdaMagica
1 sibling, 1 reply; 9+ messages in thread
From: L Dries @ 2019-11-01 10:33 UTC (permalink / raw)
To: AdaMagica
Op 1-11-2019 om 10:34 schreef AdaMagica:
> Am Freitag, 1. November 2019 09:32:42 UTC+1 schrieb L Dries:
>> I have an need for an array of Unbounded_Strings in which i define the
>> elements.
>>
>> I declared it as:
>>
> type Container is record
> ...
>> Debug_Proc : array (1 .. nr_Proc) of Unbounded_String :=
>> (Debug_Proc(Lan),
>> To_Unbounded_String("Only"),
>> To_Unbounded_String("Empty_Buffer"),
>> ...
>> etc.
> end record;
>>
>> Then I got the message:
>>
>> 65:22 Anonymous array not allowed as components
>> This results i a position just before "array"
>
> Reading the compiler message, I get the impression that your Debug_Prog is a component of another record. Just define a matching type and use an object of this type as component.
>
I just found the following solution
type Combo_Entry is array (1 .. nr_Proc) of Unbounded_String;
Debug_Proc : Combo_Entry :=
(Debug_NoProc(Lan),
To_Unbounded_String("Only"),
To_Unbounded_String("Empty_Buffer"),
...
This does not give the error anymore
--
L. Dries
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Anonymous array not allowed as components
2019-11-01 8:32 Anonymous array not allowed as components L Dries
2019-11-01 9:34 ` joakimds
2019-11-01 9:34 ` AdaMagica
@ 2019-11-01 10:41 ` Jeffrey R. Carter
2 siblings, 0 replies; 9+ messages in thread
From: Jeffrey R. Carter @ 2019-11-01 10:41 UTC (permalink / raw)
On 11/1/19 9:32 AM, L Dries wrote:
>
> Then I got the message:
>
> 65:22 Anonymous array not allowed as components
>
> What do I do wrong?
From the error msg, I would guess that you're trying to use an anonymous array
as a component. As the msg says, this is not allowed. You need to use a named
array type.
--
Jeff Carter
"It is the German who is so uncourteous to his verbs."
A Scandal in Bohemia
122
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Anonymous array not allowed as components
2019-11-01 9:34 ` joakimds
2019-11-01 10:00 ` L Dries
@ 2019-11-01 10:47 ` Jeffrey R. Carter
1 sibling, 0 replies; 9+ messages in thread
From: Jeffrey R. Carter @ 2019-11-01 10:47 UTC (permalink / raw)
On 11/1/19 10:34 AM, joakimds@kth.se wrote:
>
> Unbounded_String is well-known for being "slow" ...
I worked on a fairly large, distributed, soft-real-time system that made
extensive use of Unbounded_String, so it's certainly "fast" enough for that.
Nothing is "slow" or "fast" in isolation; such concepts are meaningful only in
comparison to quantified timing requirements. Statements like this are only
encouragement to commit premature optimization.
--
Jeff Carter
"It is the German who is so uncourteous to his verbs."
A Scandal in Bohemia
122
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Anonymous array not allowed as components
2019-11-01 10:33 ` L Dries
@ 2019-11-01 15:55 ` AdaMagica
0 siblings, 0 replies; 9+ messages in thread
From: AdaMagica @ 2019-11-01 15:55 UTC (permalink / raw)
Am Freitag, 1. November 2019 11:33:57 UTC+1 schrieb L Dries:
> I just found the following solution
>
> type Combo_Entry is array (1 .. nr_Proc) of Unbounded_String;
>
> Debug_Proc : Combo_Entry :=
> (Debug_NoProc(Lan),
> To_Unbounded_String("Only"),
> To_Unbounded_String("Empty_Buffer"),
> ...
>
> This does not give the error anymore
>
> --
> L. Dries
Yes, that's exactly what I meant.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2019-11-01 15:55 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-01 8:32 Anonymous array not allowed as components L Dries
2019-11-01 9:34 ` joakimds
2019-11-01 10:00 ` L Dries
2019-11-01 10:47 ` Jeffrey R. Carter
2019-11-01 9:34 ` AdaMagica
2019-11-01 9:56 ` L Dries
2019-11-01 10:33 ` L Dries
2019-11-01 15:55 ` AdaMagica
2019-11-01 10:41 ` Jeffrey R. Carter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox