comp.lang.ada
 help / color / mirror / Atom feed
* Cannot initialize entities of limited type?
@ 2007-01-12 13:52 Maciej Sobczak
  2007-01-12 14:04 ` Martin Krischik
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Maciej Sobczak @ 2007-01-12 13:52 UTC (permalink / raw)


Hi,

procedure Hello is

    package P is
       type T is limited private;
       function Constructor return T;
    private
       type T is new Integer;
    end P;

    package body P is
       function Constructor return T is
       begin
          return 7;
       end Constructor;
    end P;

    X : P.T := P.Constructor;  -- line 17

begin
    null;
end Hello;

$ gnatmake hello
gcc -c hello.adb
hello.adb:17:16: cannot initialize entities of limited type
gnatmake: "hello.adb" compilation error
$

I got lost. What's wrong in the code above?

-- 
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/



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

* Re: Cannot initialize entities of limited type?
  2007-01-12 13:52 Cannot initialize entities of limited type? Maciej Sobczak
@ 2007-01-12 14:04 ` Martin Krischik
  2007-01-12 14:28   ` Maciej Sobczak
  2007-01-12 19:08   ` Jeffrey Creem
  2007-01-12 14:23 ` Jean-Pierre Rosen
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 12+ messages in thread
From: Martin Krischik @ 2007-01-12 14:04 UTC (permalink / raw)


Maciej Sobczak schrieb:
> Hi,
> 
> procedure Hello is
> 
>    package P is
>       type T is limited private;
>       function Constructor return T;
>    private
>       type T is new Integer;
>    end P;
> 
>    package body P is
>       function Constructor return T is
>       begin
>          return 7;
>       end Constructor;
>    end P;
> 
>    X : P.T := P.Constructor;  -- line 17
> 
> begin
>    null;
> end Hello;
> 
> $ gnatmake hello
> gcc -c hello.adb
> hello.adb:17:16: cannot initialize entities of limited type
> gnatmake: "hello.adb" compilation error
> $
> 
> I got lost. What's wrong in the code above?

You are using a new Ada 2005 feature which your compiler may not yet 
support. Update your compiler or use:

procedure Constructor (X: in out T);

Martin



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

* Re: Cannot initialize entities of limited type?
  2007-01-12 13:52 Cannot initialize entities of limited type? Maciej Sobczak
  2007-01-12 14:04 ` Martin Krischik
@ 2007-01-12 14:23 ` Jean-Pierre Rosen
  2007-01-12 14:26 ` Jeffrey Creem
  2007-01-15 23:53 ` Jeffrey Carter
  3 siblings, 0 replies; 12+ messages in thread
From: Jean-Pierre Rosen @ 2007-01-12 14:23 UTC (permalink / raw)


Maciej Sobczak a �crit :
> I got lost. What's wrong in the code above?
> 
As the message says: you cannot initialize an entity of a limited type.

In Ada95, initialization is considered an assignment, and assignments 
are prohibited for limited types (that's what limited types are about).

This has changed in Ada 2005, initialization is now allowed (but of 
course, assignment is not).

-- 
---------------------------------------------------------
            J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



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

* Re: Cannot initialize entities of limited type?
  2007-01-12 13:52 Cannot initialize entities of limited type? Maciej Sobczak
  2007-01-12 14:04 ` Martin Krischik
  2007-01-12 14:23 ` Jean-Pierre Rosen
@ 2007-01-12 14:26 ` Jeffrey Creem
  2007-01-15 23:53 ` Jeffrey Carter
  3 siblings, 0 replies; 12+ messages in thread
From: Jeffrey Creem @ 2007-01-12 14:26 UTC (permalink / raw)


Maciej Sobczak wrote:
> Hi,
> 
> procedure Hello is
> 
>    package P is
>       type T is limited private;
>       function Constructor return T;
>    private
>       type T is new Integer;
>    end P;
> 
>    package body P is
>       function Constructor return T is
>       begin
>          return 7;
>       end Constructor;
>    end P;
> 
>    X : P.T := P.Constructor;  -- line 17
> 
> begin
>    null;
> end Hello;
> 
> $ gnatmake hello
> gcc -c hello.adb
> hello.adb:17:16: cannot initialize entities of limited type
> gnatmake: "hello.adb" compilation error
> $
> 
> I got lost. What's wrong in the code above?
> 

Hmm.. I don't think anything is wrong with it. Obviously it is a little 
odd to nest a package in the mainline procedure like that but I assume 
this was just for demo purposes.

What version of gnat and/or gcc are you using? This appears to work for 
me with a newer version of gcc (development version based on GCC SVN 
trunk) and fails with an older version.



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

* Re: Cannot initialize entities of limited type?
  2007-01-12 14:04 ` Martin Krischik
@ 2007-01-12 14:28   ` Maciej Sobczak
  2007-01-12 15:06     ` Jean-Pierre Rosen
  2007-01-13 17:39     ` Georg Bauhaus
  2007-01-12 19:08   ` Jeffrey Creem
  1 sibling, 2 replies; 12+ messages in thread
From: Maciej Sobczak @ 2007-01-12 14:28 UTC (permalink / raw)


Martin Krischik wrote:

>> $ gnatmake hello
>> gcc -c hello.adb
>> hello.adb:17:16: cannot initialize entities of limited type
>> gnatmake: "hello.adb" compilation error
>> $
>>
>> I got lost. What's wrong in the code above?
> 
> You are using a new Ada 2005 feature which your compiler may not yet 
> support.

GNAT GPL 2005 (20050729)

Not 2005'ish enough? :-)

> Update your compiler  or use:
> 
> procedure Constructor (X: in out T);

OK, I will try this for the time being.


-- 
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/



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

* Re: Cannot initialize entities of limited type?
  2007-01-12 14:28   ` Maciej Sobczak
@ 2007-01-12 15:06     ` Jean-Pierre Rosen
  2007-01-12 20:56       ` Simon Wright
  2007-01-13 17:39     ` Georg Bauhaus
  1 sibling, 1 reply; 12+ messages in thread
From: Jean-Pierre Rosen @ 2007-01-12 15:06 UTC (permalink / raw)


Maciej Sobczak a �crit :
> GNAT GPL 2005 (20050729)
> 
> Not 2005'ish enough? :-)
> 
There is a newer version of GNAT (GPL 2006). It may not have been 
supported under this version.

Also: make sure you don't have the -gnat95 option (-gnat05 is supposed 
to be the default with GNAT GPL).

-- 
---------------------------------------------------------
            J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



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

* Re: Cannot initialize entities of limited type?
  2007-01-12 14:04 ` Martin Krischik
  2007-01-12 14:28   ` Maciej Sobczak
@ 2007-01-12 19:08   ` Jeffrey Creem
  1 sibling, 0 replies; 12+ messages in thread
From: Jeffrey Creem @ 2007-01-12 19:08 UTC (permalink / raw)


Martin Krischik wrote:

>>
>> $ gnatmake hello
>> gcc -c hello.adb
>> hello.adb:17:16: cannot initialize entities of limited type
>> gnatmake: "hello.adb" compilation error
>> $
>>
>> I got lost. What's wrong in the code above?
> 
> 
> You are using a new Ada 2005 feature which your compiler may not yet 
> support. Update your compiler or use:
> 
> procedure Constructor (X: in out T);
> 
> Martin

Ah.. Of course that is a pretty obvious response to the original 
question that I totally missed. Woops!



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

* Re: Cannot initialize entities of limited type?
  2007-01-12 15:06     ` Jean-Pierre Rosen
@ 2007-01-12 20:56       ` Simon Wright
  0 siblings, 0 replies; 12+ messages in thread
From: Simon Wright @ 2007-01-12 20:56 UTC (permalink / raw)


Jean-Pierre Rosen <rosen@adalog.fr> writes:

> Maciej Sobczak a �crit :
>> GNAT GPL 2005 (20050729)
>>
>> Not 2005'ish enough? :-)
>>
> There is a newer version of GNAT (GPL 2006). It may not have been
> supported under this version.
>
> Also: make sure you don't have the -gnat95 option (-gnat05 is supposed
> to be the default with GNAT GPL).

in GNAT GPL 2005, the default is -gnat95
in GNAT GPL 2006, the default is -gnat05

gnatmake -h for the info



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

* Re: Cannot initialize entities of limited type?
  2007-01-12 14:28   ` Maciej Sobczak
  2007-01-12 15:06     ` Jean-Pierre Rosen
@ 2007-01-13 17:39     ` Georg Bauhaus
  1 sibling, 0 replies; 12+ messages in thread
From: Georg Bauhaus @ 2007-01-13 17:39 UTC (permalink / raw)


On Fri, 2007-01-12 at 15:28 +0100, Maciej Sobczak wrote:

> > Update your compiler  or use:
> > 
> > procedure Constructor (X: in out T);
> 
> OK, I will try this for the time being.
> 

FWIW, a somewhat indirect method of guaranteed initialisation
can can use a constructor function that

- takes an access to a limited object
- returns one component of the object

type T is limited record
  data : Integer := Constructor(T'access);
  -- ...
end record;

If everything that Constructor needs is in scope, this should do
the trick.





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

* Re: Cannot initialize entities of limited type?
  2007-01-12 13:52 Cannot initialize entities of limited type? Maciej Sobczak
                   ` (2 preceding siblings ...)
  2007-01-12 14:26 ` Jeffrey Creem
@ 2007-01-15 23:53 ` Jeffrey Carter
  2007-01-16  8:35   ` Maciej Sobczak
  3 siblings, 1 reply; 12+ messages in thread
From: Jeffrey Carter @ 2007-01-15 23:53 UTC (permalink / raw)


Maciej Sobczak wrote:
> 
> $ gnatmake hello
> gcc -c hello.adb
> hello.adb:17:16: cannot initialize entities of limited type
> gnatmake: "hello.adb" compilation error

gnatmake -gnat05 hello



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

* Re: Cannot initialize entities of limited type?
  2007-01-15 23:53 ` Jeffrey Carter
@ 2007-01-16  8:35   ` Maciej Sobczak
  2007-01-16 13:56     ` Martin Krischik
  0 siblings, 1 reply; 12+ messages in thread
From: Maciej Sobczak @ 2007-01-16  8:35 UTC (permalink / raw)


Jeffrey Carter wrote:

>> $ gnatmake hello
>> gcc -c hello.adb
>> hello.adb:17:16: cannot initialize entities of limited type
>> gnatmake: "hello.adb" compilation error
> 
> gnatmake -gnat05 hello

Well, there are so many similar replies that I think I will clarify this 
issue.
I'm using -gnat05 option all the time, no matter what.
To be more precise, I'm using this sequence of options:

-gnat05 -gnatv -gnatVa -gnatwe -gnatwa -gnatwd -gnatwh -gnato -gnata 
-gnaty3abcefhiklM100noprux -fstack-check

It just looks like my compiler is half-way Ada2005 and when compiling 
with -gnatv it presents itself as:

GNAT GPL 2005 (20050729)

It lacks many Ada2005 features, not only construction functions for 
limited objects. Some other that I came across are the overriding 
keyword and raise with. There are certainly others as well.

-- 
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/



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

* Re: Cannot initialize entities of limited type?
  2007-01-16  8:35   ` Maciej Sobczak
@ 2007-01-16 13:56     ` Martin Krischik
  0 siblings, 0 replies; 12+ messages in thread
From: Martin Krischik @ 2007-01-16 13:56 UTC (permalink / raw)


Maciej Sobczak schrieb:

> It just looks like my compiler is half-way Ada2005 and when compiling 
> with -gnatv it presents itself as:

Sure it is, the standard brand new and was only finished in 2006. Not 
unusual - the C/C++ standards where barely finished in the year there 
claim as well. And Fortran 2003 was published 30 November 2004 (at CHF 
340,-- damm expensive compared to $18,-- for C/C++ and $0,-- for Ada).

> GNAT GPL 2005 (20050729)
> 
> It lacks many Ada2005 features, not only construction functions for 
> limited objects. Some other that I came across are the overriding 
> keyword and raise with. There are certainly others as well.

Well there is GNAT GPL 2006 available which has more Ada 2005 features. 
Ok, still not all but at least the Ada vendors try hard for standard 
compliance.

Martin



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

end of thread, other threads:[~2007-01-16 13:56 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-12 13:52 Cannot initialize entities of limited type? Maciej Sobczak
2007-01-12 14:04 ` Martin Krischik
2007-01-12 14:28   ` Maciej Sobczak
2007-01-12 15:06     ` Jean-Pierre Rosen
2007-01-12 20:56       ` Simon Wright
2007-01-13 17:39     ` Georg Bauhaus
2007-01-12 19:08   ` Jeffrey Creem
2007-01-12 14:23 ` Jean-Pierre Rosen
2007-01-12 14:26 ` Jeffrey Creem
2007-01-15 23:53 ` Jeffrey Carter
2007-01-16  8:35   ` Maciej Sobczak
2007-01-16 13:56     ` Martin Krischik

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