* simple code can't compiled, without clear compiler warning (not clear enough to me at least)
@ 2017-11-29 15:17 Mehdi Saada
2017-11-29 15:48 ` pascal.malaise
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Mehdi Saada @ 2017-11-29 15:17 UTC (permalink / raw)
I am learning and training through the Aix en Provence Ada courses.
I coded for the first time things more substantial than reading or writing strings. Neither the specification or the body can compile, and I can't see why.
generic
type Element_type is (<>);
type Indice_type is (<>);
type Tableau_type is array (Indice_type range <>) of Element_type;
package Tri_selection is
procedure tri (T: in out Tableau_type);
end Tri_selection;
$ gcc-6 -c tri_selection.ads
cannot generate code for file tri_selection.ads (package spec)
gnatmake: "tri_selection.ads" compilation error
I thought specifications could be compiled separately ?
the body can't compiled either.
package body Tri_selection is
temp : Element_type;
procedure tri (T: in out Tableau_type) is
procedure Swap (T: in out Tableau_type; A, B : in out Element_type) is
temp: Element_type;
begin
temp := T(A);
T(A) := T(B);
T(B) := T(A);
end Swap;
temp: Indice_type;
begin
for I in Tableau_type'Range loop
for J in I..Tableau_type'Last loop
if T(J) < T(Tableau_type'Last) then temp := J;
end if;
end loop;
Swap (T,temp,Tableau_type'Last);
end loop;
end tri;
end Tri_selection;
mehdi@debian:~/essai$ gnatmake tri_selection.adb
gcc-6 -c tri_selection.adb
tri_selection.adb:7:35: expected type "Indice_type" defined at tri_selection.ads:3
tri_selection.adb:7:35: found type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:8:27: expected type "Indice_type" defined at tri_selection.ads:3
tri_selection.adb:8:27: found type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:8:35: expected type "Indice_type" defined at tri_selection.ads:3
tri_selection.adb:8:35: found type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:9:27: expected type "Indice_type" defined at tri_selection.ads:3
tri_selection.adb:9:27: found type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:9:35: expected type "Indice_type" defined at tri_selection.ads:3
tri_selection.adb:9:35: found type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:19:33: expected type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:19:33: found type "Indice_type" defined at tri_selection.ads:3
gnatmake: "tri_selection.adb" compilation error
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: simple code can't compiled, without clear compiler warning (not clear enough to me at least)
2017-11-29 15:17 simple code can't compiled, without clear compiler warning (not clear enough to me at least) Mehdi Saada
@ 2017-11-29 15:48 ` pascal.malaise
2017-11-29 16:11 ` A. Cervetti
2017-11-29 17:27 ` Mehdi Saada
2 siblings, 0 replies; 5+ messages in thread
From: pascal.malaise @ 2017-11-29 15:48 UTC (permalink / raw)
Le mercredi 29 novembre 2017 16:17:03 UTC+1, Mehdi Saada a écrit :
> $ gcc-6 -c tri_selection.ads
> cannot generate code for file tri_selection.ads (package spec)
> gnatmake: "tri_selection.ads" compilation error
>
> I thought specifications could be compiled separately ?
In fact GNAT compiles the spec (no error in this case) but does not generate the code associated to it?
> temp := T(A);
T is an array, indexed by Indice_Type, of elements of type Element_Type.
Swap shall swap two elements of T knwowing the *indexes* of elements.
You should declare:
procedure Swap (T: in out Tableau_type; I, J : in out Indice_Type)
and implement it and call it accordingly.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: simple code can't compiled, without clear compiler warning (not clear enough to me at least)
2017-11-29 15:17 simple code can't compiled, without clear compiler warning (not clear enough to me at least) Mehdi Saada
2017-11-29 15:48 ` pascal.malaise
@ 2017-11-29 16:11 ` A. Cervetti
2017-11-29 17:27 ` Mehdi Saada
2 siblings, 0 replies; 5+ messages in thread
From: A. Cervetti @ 2017-11-29 16:11 UTC (permalink / raw)
wednesday 29 november 2017 16:17:03 UTC+1, Mehdi Saada wrote:
> $ gcc-6 -c tri_selection.ads
> cannot generate code for file tri_selection.ads (package spec)
> gnatmake: "tri_selection.ads" compilation error
>
> I thought specifications could be compiled separately ?
Yes, they can, but for syntax check only. They cannot generate code (like explained in the message).
try: gcc-6 -gnats -c tri_selection.ads
>
> the body can't compiled either.
> gcc-6 -c tri_selection.adb
> tri_selection.adb:7:35: expected type "Indice_type" defined at tri_selection.ads:3
> tri_selection.adb:7:35: found type "Element_type" defined at tri_selection.ads:2
> tri_selection.adb:8:27: expected type "Indice_type" defined at tri_selection.ads:3
> tri_selection.adb:8:27: found type "Element_type" defined at tri_selection.ads:2
> tri_selection.adb:8:35: expected type "Indice_type" defined at tri_selection.ads:3
> tri_selection.adb:8:35: found type "Element_type" defined at tri_selection.ads:2
> tri_selection.adb:9:27: expected type "Indice_type" defined at tri_selection.ads:3
> tri_selection.adb:9:27: found type "Element_type" defined at tri_selection.ads:2
> tri_selection.adb:9:35: expected type "Indice_type" defined at tri_selection.ads:3
> tri_selection.adb:9:35: found type "Element_type" defined at tri_selection.ads:2
> tri_selection.adb:19:33: expected type "Element_type" defined at tri_selection.ads:2
> tri_selection.adb:19:33: found type "Indice_type" defined at tri_selection.ads:3
> gnatmake: "tri_selection.adb" compilation error
I think that the message are enough self explicative.
You defined the parameters A and B as Element_Type:
> procedure Swap (T: in out Tableau_type; A, B : in out Element_type)
than you used them as indexes:
> temp := T(A);
> T(A) := T(B);
the indexes should be Indice_type.
also you called Swap with the actual parameter temp and Tableau_type'Last
that are Index_type.
redefine Swap as
procedure Swap (T: in out Tableau_type; A, B : in out indice_type)
Now there are other errors, but I'll leave to you the pleasure of discovery.
A.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: simple code can't compiled, without clear compiler warning (not clear enough to me at least)
2017-11-29 15:17 simple code can't compiled, without clear compiler warning (not clear enough to me at least) Mehdi Saada
2017-11-29 15:48 ` pascal.malaise
2017-11-29 16:11 ` A. Cervetti
@ 2017-11-29 17:27 ` Mehdi Saada
2017-11-29 18:37 ` AdaMagica
2 siblings, 1 reply; 5+ messages in thread
From: Mehdi Saada @ 2017-11-29 17:27 UTC (permalink / raw)
Indeed, I found it. Now it works... I mean it compiled. Haven't use it in a actual program yet. I'm not used to going to the column number indicated.
But I could compile it both with Tableau_type'Last and T'Last. The manual says:
"The following attributes are defined for a prefix A that is of an array type (after any implicit dereference), or denotes a constrained array subtype"
That means I should rather put T'Last, since my generic formal type parameter for the Tabeau_type is unconstrained, so the library can't know if the provided subtype will or not be bound ?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: simple code can't compiled, without clear compiler warning (not clear enough to me at least)
2017-11-29 17:27 ` Mehdi Saada
@ 2017-11-29 18:37 ` AdaMagica
0 siblings, 0 replies; 5+ messages in thread
From: AdaMagica @ 2017-11-29 18:37 UTC (permalink / raw)
Am Mittwoch, 29. November 2017 18:27:56 UTC+1 schrieb Mehdi Saada:
>
> That means I should rather put T'Last, since my generic formal type parameter for the Tabeau_type is unconstrained, so the library can't know if the provided subtype will or not be bound ?
That's correct.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-11-29 18:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-29 15:17 simple code can't compiled, without clear compiler warning (not clear enough to me at least) Mehdi Saada
2017-11-29 15:48 ` pascal.malaise
2017-11-29 16:11 ` A. Cervetti
2017-11-29 17:27 ` Mehdi Saada
2017-11-29 18:37 ` AdaMagica
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox