comp.lang.ada
 help / color / mirror / Atom feed
* Invalid operator name?
@ 2004-11-27 16:23 Sandro Magi
  2004-11-27 16:50 ` Stephen Leake
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sandro Magi @ 2004-11-27 16:23 UTC (permalink / raw)


When I try to define my own operator, I receive an "Invalid operator name"
error during compilation. I've found references to operator overloading in
reference materials, but no word whether new operators can be defined which
leads me to believe that it's not possible.

Is it not possible to define new operators for a custom type? Can we only 
override the base operators?



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

* Re: Invalid operator name?
  2004-11-27 16:23 Invalid operator name? Sandro Magi
@ 2004-11-27 16:50 ` Stephen Leake
  2004-11-27 19:21 ` Martin Krischik
  2004-11-27 21:47 ` David C. Hoos, Sr.
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Leake @ 2004-11-27 16:50 UTC (permalink / raw)
  To: comp.lang.ada

Sandro Magi <smagi@naasking.homeip.net> writes:

> When I try to define my own operator, I receive an "Invalid operator name"
> error during compilation. I've found references to operator overloading in
> reference materials, but no word whether new operators can be defined which
> leads me to believe that it's not possible.

Right; only the predefined operators may be overloaded. That
simplifies the front end of the Ada parser, and makes it easier for
everyone to read your code.

-- 
-- Stephe




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

* Re: Invalid operator name?
  2004-11-27 16:23 Invalid operator name? Sandro Magi
  2004-11-27 16:50 ` Stephen Leake
@ 2004-11-27 19:21 ` Martin Krischik
  2004-11-27 21:47 ` David C. Hoos, Sr.
  2 siblings, 0 replies; 4+ messages in thread
From: Martin Krischik @ 2004-11-27 19:21 UTC (permalink / raw)


Sandro Magi wrote:

> When I try to define my own operator, I receive an "Invalid operator name"
> error during compilation. I've found references to operator overloading in
> reference materials, but no word whether new operators can be defined
> which leads me to believe that it's not possible.
> 
> Is it not possible to define new operators for a custom type? Can we only
> override the base operators?

Right, only the base operators can be overloaded.  See the following list:

http://en.wikibooks.org/wiki/Programming:Ada:Operators

However, Operators can be overloaded by Return type as well. See some of the
options used for "*", where the "*" operator my return a String,
Bounded_String or Unbounded_String depending on destination type.

http://en.wikibooks.org/wiki/Programming:Ada:Operators:*

But beware: to exotic uses for operators make the code more hard to read!

With Regards

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



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

* Re: Invalid operator name?
  2004-11-27 16:23 Invalid operator name? Sandro Magi
  2004-11-27 16:50 ` Stephen Leake
  2004-11-27 19:21 ` Martin Krischik
@ 2004-11-27 21:47 ` David C. Hoos, Sr.
  2 siblings, 0 replies; 4+ messages in thread
From: David C. Hoos, Sr. @ 2004-11-27 21:47 UTC (permalink / raw)
  To: Sandro Magi; +Cc: comp.lang.ada

As with many of the questions posed in this newsgroup, the
answer is given explicitly in the Ada Reference Manual.

Allow me to quote the relevant excerpt:

4.5 Operators and Expression Evaluation

1 The language defines the following six categories of operators (given in order of increasing 
precedence). The corresponding operator_symbols, and only those, can be used as designators in 
declarations of functions for user-defined operators. See 6.6, "Overloading of Operators".

Syntax

2 logical_operator ::=  and  |  or  |  xor
3 relational_operator ::=  =  |  /=  |  <  |  <=  |  >  |  >=
4 binary_adding_operator ::=  +  |  -  |  &
5 unary_adding_operator ::=  +  |  -
6 multiplying_operator ::=  *  |  /  |  mod  |  rem

7 highest_precedence_operator ::=  **  |  abs  |  not

Please note the words "and only those" near the middle of the second line of 4.5(1)

----- Original Message ----- 
From: "Sandro Magi" <smagi@naasking.homeip.net>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada-france.org>
Sent: November 27, 2004 10:23 AM
Subject: Invalid operator name?


> When I try to define my own operator, I receive an "Invalid operator name"
> error during compilation. I've found references to operator overloading in
> reference materials, but no word whether new operators can be defined which
> leads me to believe that it's not possible.
>
> Is it not possible to define new operators for a custom type? Can we only
> override the base operators?
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
>
> 




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

end of thread, other threads:[~2004-11-27 21:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-27 16:23 Invalid operator name? Sandro Magi
2004-11-27 16:50 ` Stephen Leake
2004-11-27 19:21 ` Martin Krischik
2004-11-27 21:47 ` David C. Hoos, Sr.

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