comp.lang.ada
 help / color / mirror / Atom feed
* expect procedure name in procedure call(newbie)
@ 2004-12-29 10:37 R
  2004-12-29 12:07 ` Florian Weimer
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: R @ 2004-12-29 10:37 UTC (permalink / raw)


Hello.

I've got 'expect procedure name in procedure call' warning but
I think my code is good
Inside testclass.adb I have Create function and when I'm trying to call
it from
main.adb unit I receive that error.

Below are full codes of my Ada units.

And by the way - how can I dynamically allocate memory for e.g. 10
elements(array of Floats)?
How can I reallocate them to 20 elements or 4?
How can I free the memory?

thanks in advance
best regards R

Codes:

main.adb:
--------
with testclass;
procedure Main is
object : testclass.rec1_Access;
begin
testclass.Create(object, 10);
end Main;

testclass.ads:
--------------
package testclass is
type rec1 is tagged private;
type rec1_Access is access rec1;
function Create(this: rec1_Access; s: Integer) return Integer;
private
type rec1 is tagged record
field: Integer;
end record;
end testclass;

testclass.adb:
--------------
package body testclass is
function Create(this: rec1_Access; s: Integer) return Integer is
begin
this.field :=s;
		return this.field;
	end Create;
end testclass;




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

* Re: expect procedure name in procedure call(newbie)
  2004-12-29 10:37 expect procedure name in procedure call(newbie) R
@ 2004-12-29 12:07 ` Florian Weimer
  2004-12-29 13:03   ` R
  2004-12-29 12:32 ` Martin Dowie
  2004-12-29 18:46 ` Martin Krischik
  2 siblings, 1 reply; 7+ messages in thread
From: Florian Weimer @ 2004-12-29 12:07 UTC (permalink / raw)


> testclass.Create(object, 10);

You are ignoring the return value of Create, which is not allowed.



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

* Re: expect procedure name in procedure call(newbie)
  2004-12-29 10:37 expect procedure name in procedure call(newbie) R
  2004-12-29 12:07 ` Florian Weimer
@ 2004-12-29 12:32 ` Martin Dowie
  2004-12-29 12:34   ` Martin Dowie
  2004-12-29 18:46 ` Martin Krischik
  2 siblings, 1 reply; 7+ messages in thread
From: Martin Dowie @ 2004-12-29 12:32 UTC (permalink / raw)


R wrote:
> Hello.
> 
> I've got 'expect procedure name in procedure call' warning but
> I think my code is good
> Inside testclass.adb I have Create function and when I'm trying to call
> it from
> main.adb unit I receive that error.
> 
> Below are full codes of my Ada units.
> 
> And by the way - how can I dynamically allocate memory for e.g. 10
> elements(array of Floats)?
> How can I reallocate them to 20 elements or 4?
> How can I free the memory?

In Ada you don't need to play around with memory 
allocation/reallocation/deallocation as much in other lower level 
languages. If you know in advance the maximum number you are going to 
have then you could use a discriminated array, e.g.

    type Number_Of_Floats is range 0 .. 20;
    --  Never going to be more than 20.

    type Array_Of_Floats is array (Number_Of_Floats range <>) of Float;

    type Group_Of_Floats (Length : Number_Of_Floats := 0) is record
       F : Array_Of_Floats (1 .. Length);
    end record;

    My_Floats : Group_Of_Floats;
begin
    ...

If you really don't know the number of items you are going to have then 
use one of the many container libraries available - you wouldn't 
re-invent the wheel and re-code the STL if you were using C++ would you?

Here is a link to a page of such libraries:

http://www.adapower.com/index.php?Command=Class&ClassID=AdaLibs&Title=Ada+Libraries

Look under "Data Types".

Cheers

-- Martin



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

* Re: expect procedure name in procedure call(newbie)
  2004-12-29 12:32 ` Martin Dowie
@ 2004-12-29 12:34   ` Martin Dowie
  0 siblings, 0 replies; 7+ messages in thread
From: Martin Dowie @ 2004-12-29 12:34 UTC (permalink / raw)


Martin Dowie wrote:
> In Ada you don't need to play around with memory 
> allocation/reallocation/deallocation as much in other lower level 
> languages. If you know in advance the maximum number you are going to 
> have then you could use a discriminated array, e.g.

Typo - that should be a "discriminated record".



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

* Re: expect procedure name in procedure call(newbie)
  2004-12-29 12:07 ` Florian Weimer
@ 2004-12-29 13:03   ` R
  2004-12-29 13:24     ` Mark Lorenzen
  0 siblings, 1 reply; 7+ messages in thread
From: R @ 2004-12-29 13:03 UTC (permalink / raw)


OK so i added new variable ret(Integer) and added:
ret := testclass.Create(object, 10);

but now Create raises an expception: CONSTRAINT_ERROR : testclass.adb:5
access check failed

where the Create looks like:
function Create(this: rec1_Access; s: Integer) return Integer is
begin
this.field := s; -- this is the 5th line - access check error
return this.field;
end Create;

basicly  the codes are the same from my first post - I only folow Your
instuction not to ignore the return value.

Is my access type wrong? it point to rec1 tagged record.
thanks in advance for Your help
best regards R




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

* Re: expect procedure name in procedure call(newbie)
  2004-12-29 13:03   ` R
@ 2004-12-29 13:24     ` Mark Lorenzen
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Lorenzen @ 2004-12-29 13:24 UTC (permalink / raw)


"R" <ruthless@poczta.onet.pl> writes:

> OK so i added new variable ret(Integer) and added:
> ret := testclass.Create(object, 10);
> 
> but now Create raises an expception: CONSTRAINT_ERROR : testclass.adb:5
> access check failed
> 
> where the Create looks like:
> function Create(this: rec1_Access; s: Integer) return Integer is
> begin
> this.field := s; -- this is the 5th line - access check error
> return this.field;
> end Create;
> 
> basicly  the codes are the same from my first post - I only folow Your
> instuction not to ignore the return value.
> 
> Is my access type wrong? it point to rec1 tagged record.
> thanks in advance for Your help
> best regards R

The parameter 'this' is of an access type. As the actual parameter you
pass a non-initialised variable. In Ada, all variables of access type
have the value 'null' by default. So you pass 'Create' a null value
and the dereference it.

Your example seems to be a translation of a C++ function. I would do
the following instead:

1) Make 'Create' a procedure instead of a function with the following
   signature:

   Create (This : out Rec1; S : in Integer);

2) procedure Main is
     Object : Testclass.Rec1;
   begin
     Testclass.Create(Object, 10);
   end Main;

Do not fiddle around with pointers as much as you do. It seems like
you try to program in Ada the C++ way.

- Mark Lorenzen



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

* Re: expect procedure name in procedure call(newbie)
  2004-12-29 10:37 expect procedure name in procedure call(newbie) R
  2004-12-29 12:07 ` Florian Weimer
  2004-12-29 12:32 ` Martin Dowie
@ 2004-12-29 18:46 ` Martin Krischik
  2 siblings, 0 replies; 7+ messages in thread
From: Martin Krischik @ 2004-12-29 18:46 UTC (permalink / raw)


R wrote:

> Hello.
> 
> I've got 'expect procedure name in procedure call' warning but
> I think my code is good
> Inside testclass.adb I have Create function and when I'm trying to call
> it from
> main.adb unit I receive that error.
> 
> Below are full codes of my Ada units.
> 
> And by the way - how can I dynamically allocate memory for e.g. 10
> elements(array of Floats)?
> How can I reallocate them to 20 elements or 4?
> How can I free the memory?

If you learn for Hobby then I  suggest a container lib with support for
indefinite object:

http://en.wikibooks.org/wiki/Programming:Ada:Libraries:MultiPurpose:AdaCL#Components.

If not you have to do it the hard way:

http://en.wikibooks.org/wiki/Programming:Ada:Types:access

> thanks in advance
> best regards R
> 
> Codes:
> 
> main.adb:
> --------
> with testclass;
> procedure Main is
> object : testclass.rec1_Access;
> begin
> testclass.Create(object, 10);
> end Main;
> 
> testclass.ads:
> --------------
> package testclass is
> type rec1 is tagged private;
> type rec1_Access is access rec1;
> function Create(this: rec1_Access; s: Integer) return Integer;

You call the parameter this - but Create is a "static" method. Read:

http://en.wikibooks.org/wiki/Programming:Ada:OO#Primitive_operations

> private
> type rec1 is tagged record
> field: Integer;
> end record;
> end testclass;
> 
> testclass.adb:
> --------------
> package body testclass is
> function Create(this: rec1_Access; s: Integer) return Integer is
> begin
> this.field :=s;

your are aware that this is null?

> return this.field;
> end Create;
> end testclass;

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



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

end of thread, other threads:[~2004-12-29 18:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-29 10:37 expect procedure name in procedure call(newbie) R
2004-12-29 12:07 ` Florian Weimer
2004-12-29 13:03   ` R
2004-12-29 13:24     ` Mark Lorenzen
2004-12-29 12:32 ` Martin Dowie
2004-12-29 12:34   ` Martin Dowie
2004-12-29 18:46 ` Martin Krischik

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