comp.lang.ada
 help / color / mirror / Atom feed
* Re: GNAT Limitations?
  1998-01-25  0:00 ` bklungle
@ 1998-01-25  0:00   ` wanker
  1998-01-26  0:00     ` Stephen Leake
       [not found]     ` <EnECID.GyI@world.std.com>
  0 siblings, 2 replies; 12+ messages in thread
From: wanker @ 1998-01-25  0:00 UTC (permalink / raw)



In article <01bd296e$fad757c0$0e2915c0@p5120>,
bklungle <bklungle@ix.netcom.com> wrote:
>1. Read the manual

Did that.

>2. Remove Ada.

The manual told me to use Ada.  So should I do (1) then ignore
what it says?  After all I can't heed 1 & 2 at the same time.

If the LRM says one thing and GNAT is supposed to be a conforming
Ada compiler, then it is a natural assumption to think that it
would follow the Manual (or have the rules for reading manuals
changed?).


>3. Put the (n) where it belongs
>

In that case, the C/C++ to Ada document is in error.  I will see
about contacting the author/maintainer.


>enclosed
>
>with Unchecked_Deallocation;

Completely different from every manual I've seen, so reading the
manual is of zero help here.


>
>procedure Huh is
>
>  type x is
>    record
>      a : integer := 0;
>      b : integer := 0;
>      c : integer := 0;
>    end record;
>  type x_ptr is access x;
>
>  procedure dispose is new Unchecked_Deallocation(x, x_ptr);

Ok, so far so good.  I'll try this out.


>
>  an_x : x := (a => 1, b => 2, c => 3);

This was already working, the problem was that leaving out the
b caused it to not compile, and according to the manuals that
you insisted I read, it should not do that.  


>
>  type m is array(1..2, 1..3) of integer;
>  an_m : m := (others => (others => 0));
>
>begin
>  for i in an_m'range(1) loop
>    for j in an_m'range(2) loop
>      an_m(i,j) := i;
>    end loop;
>  end loop;
>end Huh;
>

Ok, I see what you mean.


>
>-- and then compile
>
>linux:~/atest> touch *.adb
>linux:~/atest> ada huh.adb
>gcc -c -g huh.adb
>gnatbind -x huh.ali
>gnatlink -g huh.ali
>linux:~/atest> 

Thank heaven for IDEs.

Thank you for all your help, although I am still annoyed at
the discrepencies between the Manuals & GNAT's behavior.  But
then it is a free tool, and even with the discrepencies it is
probably one of the better quality compilers out there.








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

* Re: GNAT Limitations?
  1998-01-25  0:00 ` Keith Thompson
@ 1998-01-25  0:00   ` wanker
  1998-01-26  0:00     ` Nick Roberts
  0 siblings, 1 reply; 12+ messages in thread
From: wanker @ 1998-01-25  0:00 UTC (permalink / raw)



In article <885721317.973387@wagasa.cts.com>,
Keith Thompson <kst@king.cts.com> wrote:
>wanker@exploited.barmy.army wrote:

[Snip -- about not being able to omit record fields with default values
 during aggregate initilization]

>It sounds like the "C/C++ to Ada" guide is either wrong or unclear.  In a
>subprogram call (which has similar syntax), you can omit some parameters
>if they have default values.  You can't do the same for record aggregates.
>(Being able to omit components with default initial values would be a
>nice feature, by the way.)

It's wrong then because in the section on records it specifically
states that you could do this.  I could post the precise example
of what it claims if anyone is interested, but it's probably
pointless - thanks.


>> 	2) When I try to instantiate Ada.Unchecked_Deallocation,
>> 		GNAT claims that Unchecked_Deallocation is not
>> 		in Ada, which contradicts what's in the Language
>> 		Referenec Manual and the "C/C++ to Ada Guide".
>> 		Again, what gives?
>
>Another poster incorrectly suggested removing "Ada." prefix; that
>shouldn't make any difference.  Do you have a "with" clause for
>Ada.Unchecked_Deallocation?  Are you sure you spelled it correctly?
>Does the following compile?

Hmmmm, guess the poster should have heeded his own advice and
read the manual ;).

[Snip]

>If not, you may have a misconfigured library; post the exact error
>message the compiler gives you.
>

I compiled a slightly different sample, but using the info
you provided and it worked beautifully, thank you.


>> 			for I in Matrix(1)'Range loop
>> 			    for J in Matrix(2)'Range loop
>> 				Some_Op (Matrix (I, J));
>> 		 	    end loop;
>> 			end loop;
>> 
>> 		The compiler complains about using an attribute
>> 		and indexing Matrix at the same time.  
>
>If Matrix is a constrained 2d array type, you can use the 'Range
>attribute on each of its dimensions, but your syntax is slightly off.
>The range of the first dimension is Matrix'Range(1); the range of the
>second dimension is Matrix'Range(2).

Right that was another error in the C/C++ to Ada transition guide.
I tried it this way and again it works perfectly.  Thanks to
both of you.


>
>If Matrix is an unconstrained type (which is more likely), you'll need to
>replace Matrix by the name of an object of type Matrix.  It's probably
>clearer to do this even if Matrix is constrained.  And, of course,
>you'll need to make the same change in Matrix (I, J).

Right, that's what I did.



>
>-- 
>Keith Thompson (The_Other_Keith) kst@cts.com <*>
>^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H
>San Diego, California, USA
>Trying to keep my daily caffeine intake between the RDA and the LD50.






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

* GNAT Limitations?
@ 1998-01-25  0:00 wanker
  1998-01-25  0:00 ` bklungle
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: wanker @ 1998-01-25  0:00 UTC (permalink / raw)



Hi all,

On GNAT 3.09 (Win95) I find two problems that I can't find mentioned
anywhere in the documentation:
	1) GNAT refuses to let me initialize a record with named
		fields if I don't initialize every field.  For
		example:

		type X is
		    record
			A : Integer := 1;
			B : Integer := 2;
			C : Integer := 3;
		    end record;

		A_Rec : X := (A => 5, C => 6);

		Gives me an error with something like "No value
		provided for B".  However, according to the
		"C/C++ to Ada" Guide I am supposed to be able
		to do this.  What gives?

	2) When I try to instantiate Ada.Unchecked_Deallocation,
		GNAT claims that Unchecked_Deallocation is not
		in Ada, which contradicts what's in the Language
		Referenec Manual and the "C/C++ to Ada Guide".
		Again, what gives?

	3) GNAT refuses to compile code where I try to find the
		range of a particular dimension of a multi-dimensional
		array.  I'm using the example in the C/C++ to
		Ada Guide:

			-- Assuming Matrix is a 2d array type
			
			for I in Matrix(1)'Range loop
			    for J in Matrix(2)'Range loop
				Some_Op (Matrix (I, J));
		 	    end loop;
			end loop;

		The compiler complains about using an attribute
		and indexing Matrix at the same time.  

Has anyone else been having any of the above problems?  If so,
is there some kind of workaround?  






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

* Re: GNAT Limitations?
  1998-01-25  0:00 GNAT Limitations? wanker
  1998-01-25  0:00 ` bklungle
@ 1998-01-25  0:00 ` Keith Thompson
  1998-01-25  0:00   ` wanker
  1998-02-18  0:00 ` Ed Colbert
  2 siblings, 1 reply; 12+ messages in thread
From: Keith Thompson @ 1998-01-25  0:00 UTC (permalink / raw)



wanker@exploited.barmy.army wrote:
> On GNAT 3.09 (Win95) I find two problems that I can't find mentioned
> anywhere in the documentation:
> 	1) GNAT refuses to let me initialize a record with named
> 		fields if I don't initialize every field.  For
> 		example:
> 
> 		type X is
> 		    record
> 			A : Integer := 1;
> 			B : Integer := 2;
> 			C : Integer := 3;
> 		    end record;
> 
> 		A_Rec : X := (A => 5, C => 6);
> 
> 		Gives me an error with something like "No value
> 		provided for B".  However, according to the
> 		"C/C++ to Ada" Guide I am supposed to be able
> 		to do this.  What gives?

It sounds like the "C/C++ to Ada" guide is either wrong or unclear.  In a
subprogram call (which has similar syntax), you can omit some parameters
if they have default values.  You can't do the same for record aggregates.
(Being able to omit components with default initial values would be a
nice feature, by the way.)

> 	2) When I try to instantiate Ada.Unchecked_Deallocation,
> 		GNAT claims that Unchecked_Deallocation is not
> 		in Ada, which contradicts what's in the Language
> 		Referenec Manual and the "C/C++ to Ada Guide".
> 		Again, what gives?

Another poster incorrectly suggested removing "Ada." prefix; that
shouldn't make any difference.  Do you have a "with" clause for
Ada.Unchecked_Deallocation?  Are you sure you spelled it correctly?
Does the following compile?

   with Ada.Unchecked_Deallocation;
   package Foo is
      type Pointer is access Integer;
      procedure Free is new Ada.Unchecked_Deallocation(Integer, Pointer);
   end Foo;

If not, you may have a misconfigured library; post the exact error
message the compiler gives you.

> 	3) GNAT refuses to compile code where I try to find the
> 		range of a particular dimension of a multi-dimensional
> 		array.  I'm using the example in the C/C++ to
> 		Ada Guide:
> 
> 			-- Assuming Matrix is a 2d array type
> 			
> 			for I in Matrix(1)'Range loop
> 			    for J in Matrix(2)'Range loop
> 				Some_Op (Matrix (I, J));
> 		 	    end loop;
> 			end loop;
> 
> 		The compiler complains about using an attribute
> 		and indexing Matrix at the same time.  

If Matrix is a constrained 2d array type, you can use the 'Range
attribute on each of its dimensions, but your syntax is slightly off.
The range of the first dimension is Matrix'Range(1); the range of the
second dimension is Matrix'Range(2).

If Matrix is an unconstrained type (which is more likely), you'll need to
replace Matrix by the name of an object of type Matrix.  It's probably
clearer to do this even if Matrix is constrained.  And, of course,
you'll need to make the same change in Matrix (I, J).

-- 
Keith Thompson (The_Other_Keith) kst@cts.com <*>
^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H
San Diego, California, USA
Trying to keep my daily caffeine intake between the RDA and the LD50.




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

* Re: GNAT Limitations?
  1998-01-25  0:00 GNAT Limitations? wanker
@ 1998-01-25  0:00 ` bklungle
  1998-01-25  0:00   ` wanker
  1998-01-25  0:00 ` Keith Thompson
  1998-02-18  0:00 ` Ed Colbert
  2 siblings, 1 reply; 12+ messages in thread
From: bklungle @ 1998-01-25  0:00 UTC (permalink / raw)



1. Read the manual
2. Remove Ada.
3. Put the (n) where it belongs

enclosed

with Unchecked_Deallocation;

procedure Huh is

  type x is
    record
      a : integer := 0;
      b : integer := 0;
      c : integer := 0;
    end record;
  type x_ptr is access x;

  procedure dispose is new Unchecked_Deallocation(x, x_ptr);

  an_x : x := (a => 1, b => 2, c => 3);

  type m is array(1..2, 1..3) of integer;
  an_m : m := (others => (others => 0));

begin
  for i in an_m'range(1) loop
    for j in an_m'range(2) loop
      an_m(i,j) := i;
    end loop;
  end loop;
end Huh;


-- and then compile

linux:~/atest> touch *.adb
linux:~/atest> ada huh.adb
gcc -c -g huh.adb
gnatbind -x huh.ali
gnatlink -g huh.ali
linux:~/atest> 


wanker@exploited.barmy.army wrote in article
<6aesm3$sr6$1@Masala.CC.UH.EDU>...
> Hi all,
> 
> On GNAT 3.09 (Win95) I find two problems that I can't find mentioned
> anywhere in the documentation:
> 	1) GNAT refuses to let me initialize a record with named
> 		fields if I don't initialize every field.  For
> 		example:
> 
> 		type X is
> 		    record
> 			A : Integer := 1;
> 			B : Integer := 2;
> 			C : Integer := 3;
> 		    end record;
> 
> 		A_Rec : X := (A => 5, C => 6);
> 
> 		Gives me an error with something like "No value
> 		provided for B".  However, according to the
> 		"C/C++ to Ada" Guide I am supposed to be able
> 		to do this.  What gives?
> 
> 	2) When I try to instantiate Ada.Unchecked_Deallocation,
> 		GNAT claims that Unchecked_Deallocation is not
> 		in Ada, which contradicts what's in the Language
> 		Referenec Manual and the "C/C++ to Ada Guide".
> 		Again, what gives?
> 
> 	3) GNAT refuses to compile code where I try to find the
> 		range of a particular dimension of a multi-dimensional
> 		array.  I'm using the example in the C/C++ to
> 		Ada Guide:
> 
> 			-- Assuming Matrix is a 2d array type
> 			
> 			for I in Matrix(1)'Range loop
> 			    for J in Matrix(2)'Range loop
> 				Some_Op (Matrix (I, J));
> 		 	    end loop;
> 			end loop;
> 
> 		The compiler complains about using an attribute
> 		and indexing Matrix at the same time.  
> 
> Has anyone else been having any of the above problems?  If so,
> is there some kind of workaround?  
> 
> 
> 




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

* Re: GNAT Limitations?
       [not found] <6aesm3$sr6$1@masala.cc.uh.edu>
@ 1998-01-25  0:00 ` wanker
  0 siblings, 0 replies; 12+ messages in thread
From: wanker @ 1998-01-25  0:00 UTC (permalink / raw)



In article <6aesm3$sr6$1@masala.cc.uh.edu>,
 <wanker@exploited.barmy.army> wrote:

Actually, one mistake I wanted to correct:


>			-- Assuming Matrix is a 2d array type
>			
>			for I in Matrix(1)'Range loop
>			    for J in Matrix(2)'Range loop
>				Some_Op (Matrix (I, J));
					 ^^^^^^
	The above line (Matrix) should be something else, namely
	a variable of type Matrix.  This was a typing mistake that
	was not in the code.


Thanks.







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

* Re: GNAT Limitations?
  1998-01-25  0:00   ` wanker
@ 1998-01-26  0:00     ` Stephen Leake
  1998-01-26  0:00       ` Nick Roberts
       [not found]     ` <EnECID.GyI@world.std.com>
  1 sibling, 1 reply; 12+ messages in thread
From: Stephen Leake @ 1998-01-26  0:00 UTC (permalink / raw)



wanker@exploited.barmy.army wrote:
> >2. Remove Ada.
> 
> The manual told me to use Ada.  So should I do (1) then ignore
> what it says?  After all I can't heed 1 & 2 at the same time.

2. with Ada.Unchecked_Deallocation;

For compatibility with Ada 83, "Unchecked_Deallocation" is declared both
in Standard (as a rename) and in Ada. To use the one in Ada, you need to
with it correctly.

> 
> If the LRM says one thing and GNAT is supposed to be a conforming
> Ada compiler, then it is a natural assumption to think that it
> would follow the Manual (or have the rules for reading manuals
> changed?).

GNAT is correct, and so is the manual. Keep asking questions; you'll
eventually get where you need to be :).

-- 
- Stephe




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

* Re: GNAT Limitations?
  1998-01-26  0:00     ` Stephen Leake
@ 1998-01-26  0:00       ` Nick Roberts
  0 siblings, 0 replies; 12+ messages in thread
From: Nick Roberts @ 1998-01-26  0:00 UTC (permalink / raw)



And nothing makes a compiler-writer's heart flutter so dangerously as a
user claiming to have found a subtle but pernicious bug in his/her product!
 (It's like walking on razor blades ;-)

-- 

Nick Roberts
Croydon, UK

Proprietor, ThoughtWing Software; Independent Software Development
Consultant
* Nick.Roberts@dial.pipex.com * Voicemail & Fax +44 181-405 1124 *
*** Always game for a verbal joust (usually as the turkey) ***


Stephen Leake <Stephen.Leake@gsfc.nasa.gov> wrote in article
<34CCAD31.2E47@gsfc.nasa.gov>...
[...]
> 
> GNAT is correct, and so is the manual. Keep asking questions; you'll
> eventually get where you need to be :).





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

* Re: GNAT Limitations?
  1998-01-25  0:00   ` wanker
@ 1998-01-26  0:00     ` Nick Roberts
  0 siblings, 0 replies; 12+ messages in thread
From: Nick Roberts @ 1998-01-26  0:00 UTC (permalink / raw)



Please, by all means, post the example.  We (well alright then, I ;-) would
be very interested!

-- 

Nick Roberts
Croydon, UK

Proprietor, ThoughtWing Software; Independent Software Development
Consultant
* Nick.Roberts@dial.pipex.com * Voicemail & Fax +44 181-405 1124 *
*** Always game for a verbal joust (usually as the turkey) ***


wanker@exploited.barmy.army wrote in article
<6afuas$vrn$1@Masala.CC.UH.EDU>...
> >It sounds like the "C/C++ to Ada" guide is either wrong or unclear.  In
a
> >subprogram call (which has similar syntax), you can omit some parameters
> >if they have default values.  You can't do the same for record
aggregates.
> >(Being able to omit components with default initial values would be a
> >nice feature, by the way.)
> 
> It's wrong then because in the section on records it specifically
> states that you could do this.  I could post the precise example
> of what it claims if anyone is interested, but it's probably
> pointless - thanks.





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

* Re: GNAT Limitations?
       [not found]       ` <EnIJ7B.8CB@world.std.com>
  1998-01-29  0:00         ` Nick Roberts
@ 1998-01-29  0:00         ` bklungle
  1 sibling, 0 replies; 12+ messages in thread
From: bklungle @ 1998-01-29  0:00 UTC (permalink / raw)



Hi Bob,

Nice to see I'm not the only one that does something silly now and then. I
should go to bed after debugging others peoples code all day instead of on
the net. Guess the groggies creep in.

cheers...bob klungle

Robert A Duff <robertduff@world.std.com> wrote in article
<EnIJ7B.8CB@world.std.com>...
> After lecturing Mr. Klungle not to lecture and then give wrong answers,
> I wrote:
> 
> >The predefined environment also contains: "package
> >Unchecked_Deallocation renames Ada.Unchecked_Deallocation;", ...
> 
> which is wrong -- it's a generic procedure, not a package, as pointed
> out to me privately by Martin David Condic.  Sorry.  The exact code is
> in RM-J.1.
> 
> - Bob
> -- 
> Change robert to bob to get my real email address.  Sorry.
> 




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

* Re: GNAT Limitations?
       [not found]       ` <EnIJ7B.8CB@world.std.com>
@ 1998-01-29  0:00         ` Nick Roberts
  1998-01-29  0:00         ` bklungle
  1 sibling, 0 replies; 12+ messages in thread
From: Nick Roberts @ 1998-01-29  0:00 UTC (permalink / raw)



Robert A Duff <robertduff@world.std.com> wrote in article
<EnIJ7B.8CB@world.std.com>...
> After lecturing Mr. Klungle not to lecture and then give wrong answers,
> I wrote:
> 
> >The predefined environment also contains: "package
> >Unchecked_Deallocation renames Ada.Unchecked_Deallocation;", ...
> 
> which is wrong -- it's a generic procedure, not a package, as pointed
> out to me privately by Martin David Condic.  Sorry.  The exact code is
> in RM-J.1.

The biter bit!

Nick ;-)




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

* Re: GNAT Limitations?
  1998-01-25  0:00 GNAT Limitations? wanker
  1998-01-25  0:00 ` bklungle
  1998-01-25  0:00 ` Keith Thompson
@ 1998-02-18  0:00 ` Ed Colbert
  2 siblings, 0 replies; 12+ messages in thread
From: Ed Colbert @ 1998-02-18  0:00 UTC (permalink / raw)




wanker@exploited.barmy.army wrote in message
<6aesm3$sr6$1@Masala.CC.UH.EDU>...
>On GNAT 3.09 (Win95) I find two problems that I can't find mentioned
>anywhere in the documentation:
> 1) GNAT refuses to let me initialize a record with named
> fields if I don't initialize every field.  For
> example:
>
> type X is
>     record
> A : Integer := 1;
> B : Integer := 2;
> C : Integer := 3;
>     end record;
>
> A_Rec : X := (A => 5, C => 6);
>
> Gives me an error with something like "No value
> provided for B".  However, according to the
> "C/C++ to Ada" Guide I am supposed to be able
> to do this.  What gives?


The problem is your aggregate does not specify a value for B.  An aggregate
must have an explicit value for each record component.  Defaults apply to
object declarations, i.e. when you declare an uninitialized object.  So if
you had declared:

    A_Rec: X;

You would get default values for A, B, & C.

> 2) When I try to instantiate Ada.Unchecked_Deallocation,
> GNAT claims that Unchecked_Deallocation is not
> in Ada, which contradicts what's in the Language
> Referenec Manual and the "C/C++ to Ada Guide".
> Again, what gives?


Did you with it before you instatiated it?  For example:

    with Ada.Unchecked_Deallocation;
    procedure Free is new Ada.Unchecked_Deallocation (...);

> 3) GNAT refuses to compile code where I try to find the
> range of a particular dimension of a multi-dimensional
> array.  I'm using the example in the C/C++ to
> Ada Guide:
>
> -- Assuming Matrix is a 2d array type
>
> for I in Matrix(1)'Range loop
>     for J in Matrix(2)'Range loop
> Some_Op (Matrix (I, J));
>     end loop;
> end loop;
>
> The compiler complains about using an attribute
> and indexing Matrix at the same time.


You have the syntax wrong.  Change your loop to the following:

 for I in Matrix'Range(1) loop
     for J in Matrix'Range(2) loop
         Some_Op (Matrix (I, J));
     end loop;
 end loop;

Take Care,
Ed Colbert







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

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

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-01-25  0:00 GNAT Limitations? wanker
1998-01-25  0:00 ` bklungle
1998-01-25  0:00   ` wanker
1998-01-26  0:00     ` Stephen Leake
1998-01-26  0:00       ` Nick Roberts
     [not found]     ` <EnECID.GyI@world.std.com>
     [not found]       ` <EnIJ7B.8CB@world.std.com>
1998-01-29  0:00         ` Nick Roberts
1998-01-29  0:00         ` bklungle
1998-01-25  0:00 ` Keith Thompson
1998-01-25  0:00   ` wanker
1998-01-26  0:00     ` Nick Roberts
1998-02-18  0:00 ` Ed Colbert
     [not found] <6aesm3$sr6$1@masala.cc.uh.edu>
1998-01-25  0:00 ` wanker

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