comp.lang.ada
 help / color / mirror / Atom feed
* Question on operator overloading
@ 2005-04-07 16:24 James Alan Farrell
  2005-04-07 16:33 ` Georg Bauhaus
  2005-04-07 18:26 ` Martin Krischik
  0 siblings, 2 replies; 4+ messages in thread
From: James Alan Farrell @ 2005-04-07 16:24 UTC (permalink / raw)


Hi all,
I'm looking at ARM 6.6 (and 4.5).  I don't see anything that disallows
in/out or out parameters when overloading an operator.  When I try to
use an in/out parameter in gnat, I get an error.  Is this disallowed?
Could there be compilers that allow it?

I'm not trying to do this.  I'm working on software to analyze Ada
programs (using ASIS) and need to cover all possible bases.

Thanks,
James Alan Farrell


with Ada.Text_IO;
use  Ada.Text_IO;

 procedure Proc1 is

      type MyInt is new Integer range 0 .. 1000;

      function "+" (Left : MyInt; Right : in out MyInt) return MyInt
is
      begin
         return MyInt(Integer(Left) + Integer(Right) + 3);
      end;

      A, B, Y : MyInt;

   begin -- proc1
      A := 1;
      B := 2;
      Y := A + B;
      Put_Line(Integer'Image(Integer(Y)));
   end Proc1;
end mod1;

=====

$> gnatmake main
gcc -c mod1.adb
mod1.adb:10:35: functions can only have "in" parameters
gnatmake: "mod1.adb" compilation error


(main simply declares a procedure that calls Proc1)



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

* Re: Question on operator overloading
  2005-04-07 16:24 Question on operator overloading James Alan Farrell
@ 2005-04-07 16:33 ` Georg Bauhaus
  2005-04-07 16:57   ` James Alan Farrell
  2005-04-07 18:26 ` Martin Krischik
  1 sibling, 1 reply; 4+ messages in thread
From: Georg Bauhaus @ 2005-04-07 16:33 UTC (permalink / raw)


James Alan Farrell wrote:

>       function "+" (Left : MyInt; Right : in out MyInt) return MyInt

"+" is a function, and functions are not allowed to make assignments
to their arguments directly.

Georg 



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

* Re: Question on operator overloading
  2005-04-07 16:33 ` Georg Bauhaus
@ 2005-04-07 16:57   ` James Alan Farrell
  0 siblings, 0 replies; 4+ messages in thread
From: James Alan Farrell @ 2005-04-07 16:57 UTC (permalink / raw)


Oops, yes, you are correct.  (I was under the impression that had
changed in Ada 95, but I see that in ARM 6.1(18).

Thanks,
James

On Thu, 07 Apr 2005 18:33:32 +0200, Georg Bauhaus
<bauhaus@futureapps.de> wrote:

>James Alan Farrell wrote:
>
>>       function "+" (Left : MyInt; Right : in out MyInt) return MyInt
>
>"+" is a function, and functions are not allowed to make assignments
>to their arguments directly.
>
>Georg 




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

* Re: Question on operator overloading
  2005-04-07 16:24 Question on operator overloading James Alan Farrell
  2005-04-07 16:33 ` Georg Bauhaus
@ 2005-04-07 18:26 ` Martin Krischik
  1 sibling, 0 replies; 4+ messages in thread
From: Martin Krischik @ 2005-04-07 18:26 UTC (permalink / raw)


James Alan Farrell wrote:

> Hi all,
> I'm looking at ARM 6.6 (and 4.5).  I don't see anything that disallows
> in/out or out parameters when overloading an operator.

But you overlooked that all operators are functions -  and therefore the
rules for functions apply.

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com




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

end of thread, other threads:[~2005-04-07 18:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-07 16:24 Question on operator overloading James Alan Farrell
2005-04-07 16:33 ` Georg Bauhaus
2005-04-07 16:57   ` James Alan Farrell
2005-04-07 18:26 ` Martin Krischik

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