comp.lang.ada
 help / color / mirror / Atom feed
From: Mark Lorenzen <mark.lorenzen@ofir.dk>
Subject: Re: expect procedure name in procedure call(newbie)
Date: 29 Dec 2004 14:24:45 +0100
Date: 2004-12-29T14:24:45+01:00	[thread overview]
Message-ID: <m3llbh6xuq.fsf@0x5358ef74.boanxx18.adsl-dhcp.tele.dk> (raw)
In-Reply-To: 1104325404.761331.70990@f14g2000cwb.googlegroups.com

"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



  reply	other threads:[~2004-12-29 13:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2004-12-29 12:32 ` Martin Dowie
2004-12-29 12:34   ` Martin Dowie
2004-12-29 18:46 ` Martin Krischik
replies disabled

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