* Problem when overloading a procedure
@ 1999-08-14 0:00 JIMHER@yanoesladirecci�n.com
1999-08-14 0:00 ` David C. Hoos, Sr.
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: JIMHER@yanoesladirecci�n.com @ 1999-08-14 0:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1115 bytes --]
I'm writing a program, and I have found a problem when I try to overload
a procedure. The program is:
procedure program is
type MyType is array(1..10) of character;
procedure proc(s:in string) is
begin
put_line("Original string");
end proc;
procedure proc(s:in MyType) is
begin
put_line("My type");
end proc;
begin
proc("hello");
end program;
The problem is that, when I compile the program, the compiler says that
is unable to select between the two forms of 'proc'. I suppose that it is
because the compiler can't decide if the literal "hello" is of type
string or MyType, so I tried
...
begin
proc(string("hello"));
end program;
but the compiler didn't accept it.
I think that it will be some language way to tell the compiler if the
literal sent to 'proc' is of type string or of type MyType, so I would
thank a lot if any one could tell me how. Also, if it can be done by
another way, it could help me too.
Thanks in advance and sorry about my english
--
Jes�s Jim�nez Herranz
vtis0102@CACANOps.uib.es
(Remove CACANO from the address)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Problem when overloading a procedure
1999-08-14 0:00 Problem when overloading a procedure JIMHER@yanoesladirecci�n.com
@ 1999-08-14 0:00 ` David C. Hoos, Sr.
1999-08-16 0:00 ` Robert Dewar
1999-08-17 0:00 ` Samuel T. Harris
2 siblings, 0 replies; 5+ messages in thread
From: David C. Hoos, Sr. @ 1999-08-14 0:00 UTC (permalink / raw)
JIMHER@yanoesladirecci�n.com <vtis0102@CACANOps.uib.es> wrote in message
news:MPG.121fca311abf8d5b98999b@news.bcn.ttd.net...
> I'm writing a program, and I have found a problem when I try to overload
> a procedure. The program is:
>
> procedure program is
>
> type MyType is array(1..10) of character;
>
> procedure proc(s:in string) is
> begin
> put_line("Original string");
> end proc;
>
> procedure proc(s:in MyType) is
> begin
> put_line("My type");
> end proc;
>
> begin
> proc("hello");
> end program;
>
> The problem is that, when I compile the program, the compiler says that
> is unable to select between the two forms of 'proc'. I suppose that it is
> because the compiler can't decide if the literal "hello" is of type
> string or MyType, so I tried
>
> ...
> begin
> proc(string("hello"));
> end program;
>
> but the compiler didn't accept it.
>
Your analysis was correct, and your solution was almost correct.
it should have been
proc(string'("hello"));
See RM 4.7
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Problem when overloading a procedure
1999-08-14 0:00 Problem when overloading a procedure JIMHER@yanoesladirecci�n.com
1999-08-14 0:00 ` David C. Hoos, Sr.
@ 1999-08-16 0:00 ` Robert Dewar
1999-08-17 0:00 ` Samuel T. Harris
2 siblings, 0 replies; 5+ messages in thread
From: Robert Dewar @ 1999-08-16 0:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 642 bytes --]
In article <MPG.121fca311abf8d5b98999b@news.bcn.ttd.net>,
vtis0102@CACANOps.uib.es (JIMHER@yanoesladirecci�n.com) wrote:
> string or MyType, so I tried
>
> ...
> begin
> proc(string("hello"));
> end program;
>
> but the compiler didn't accept it.
>
> I think that it will be some language way to tell the compiler
if the
> literal sent to 'proc' is of type string or of type MyType
Use a qualified expression (with a quote).
If you use GNAT, it would have told you that, with an
explicit msg:
program.adb:13:16: use qualified expression instead
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Problem when overloading a procedure
1999-08-14 0:00 Problem when overloading a procedure JIMHER@yanoesladirecci�n.com
1999-08-14 0:00 ` David C. Hoos, Sr.
1999-08-16 0:00 ` Robert Dewar
@ 1999-08-17 0:00 ` Samuel T. Harris
1999-08-18 0:00 ` JIMHER@yanoesladirecci�n.com
2 siblings, 1 reply; 5+ messages in thread
From: Samuel T. Harris @ 1999-08-17 0:00 UTC (permalink / raw)
"JIMHER@yanoesladirección.com" wrote:
>
> I'm writing a program, and I have found a problem when I try to overload
> a procedure. The program is:
>
> procedure program is
>
> type MyType is array(1..10) of character;
>
> procedure proc(s:in string) is
> begin
> put_line("Original string");
> end proc;
>
> procedure proc(s:in MyType) is
> begin
> put_line("My type");
> end proc;
>
> begin
> proc("hello");
> end program;
>
> The problem is that, when I compile the program, the compiler says that
> is unable to select between the two forms of 'proc'. I suppose that it is
> because the compiler can't decide if the literal "hello" is of type
> string or MyType, so I tried
>
> ...
> begin
> proc(string("hello"));
> end program;
>
As others have already pointed out, you need a "qualified expression."
What you have is a "type conversion". The difference is significant
eventhough the syntax is very similar.
string("hello") is a type conversion. It looks like a function
call but the function name is a type name. It also acts like
a function call (at least semantically since many occurances
need no code implementating them). As such, it suffers from
the original problem, namely, what type to convert from?
Just as proc can tell what type the string literal is suppose
to be, the type converter string also can't tell what type
the literal is suppose to be.
string'("hello") is a type qualification. It means what it says.
The little tick "'" after the type name makes all the difference.
This says the expression inside the parenthesis is suppose to be
of type string. Nothing happens. It is a way for the source to
resolve ambiguities, especially when several derived scalar types
are visible and literals are needed.
> but the compiler didn't accept it.
>
> I think that it will be some language way to tell the compiler if the
> literal sent to 'proc' is of type string or of type MyType, so I would
> thank a lot if any one could tell me how. Also, if it can be done by
> another way, it could help me too.
>
> Thanks in advance and sorry about my english
>
> --
> Jesús Jiménez Herranz
> vtis0102@CACANOps.uib.es
> (Remove CACANO from the address)
--
Samuel T. Harris, Principal Engineer
Raytheon, Scientific and Technical Systems
"If you can make it, We can fake it!"
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Problem when overloading a procedure
1999-08-17 0:00 ` Samuel T. Harris
@ 1999-08-18 0:00 ` JIMHER@yanoesladirecci�n.com
0 siblings, 0 replies; 5+ messages in thread
From: JIMHER@yanoesladirecci�n.com @ 1999-08-18 0:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 151 bytes --]
Thanks to all for your answers, they have helped me a lot.
--
Jes�s Jim�nez Herranz
vtis0102@CACANOps.uib.es
(Remove CACANO from the address)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1999-08-18 0:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-08-14 0:00 Problem when overloading a procedure JIMHER@yanoesladirecci�n.com
1999-08-14 0:00 ` David C. Hoos, Sr.
1999-08-16 0:00 ` Robert Dewar
1999-08-17 0:00 ` Samuel T. Harris
1999-08-18 0:00 ` JIMHER@yanoesladirecci�n.com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox