subprogram parameter list

  • Thread starter =?ISO-8859-1?Q?Sch=FCle_Daniel?=
  • Start date
?

=?ISO-8859-1?Q?Sch=FCle_Daniel?=

Hello,

I have a simple question and my book doesn't have the answer

given a procedure declaration in the package and
its definition in a package body


package X is
procedure xxx(variable a: out integer); -- a
end;

package body X is
procedure xxx(variable b: out integer) is -- b --(2)
begin
b := 1; -- (1)
end;
end;

is it allowed to rename the parameters in such way?
ghdl gives an error message at (1) that 'b' is not declared
however (2) was accepted.

Regards, Daniel
 
R

reuven

Schüle Daniel said:
Hello,

I have a simple question and my book doesn't have the answer

given a procedure declaration in the package and
its definition in a package body


package X is
procedure xxx(variable a: out integer); -- a
end;

package body X is
procedure xxx(variable b: out integer) is -- b --(2)
begin
b := 1; -- (1)
end;
end;

is it allowed to rename the parameters in such way?
ghdl gives an error message at (1) that 'b' is not declared
however (2) was accepted.

Regards, Daniel

No, it is not allowed, the procedure declaration is the interface to
the procedure implementation in the package body. How will ghdl know
the procedure body matches the interface declaration. By the way,
procedures in VHDL can be overloaded. To extend your example:

package X is
procedure xxx(variable a: out integer); -- a
procedure xxx(variable a: out real); -- a
end;

package body X is
procedure xxx(variable a: out integer) is -- b --(2)
begin
b := 1; -- (1)
end;
procedure xxx(variable a: out real) is -- b --(2)
begin
b := 1.0; -- (1)
end;
end;
 
?

=?ISO-8859-1?Q?Sch=FCle_Daniel?=

reuven said:
No, it is not allowed, the procedure declaration is the interface to
the procedure implementation in the package body. How will ghdl know
the procedure body matches the interface declaration.


I think it is more a matter of design
it would be easy to ignore the name the way C does it

int foo(int x);
int foo(int y);
int foo(int); // all the same

hence my question, whether the names are part of subprogram
signature or not.

I stumbled over this with names res <-> ret (meaning result <-> return)


By the way,
procedures in VHDL can be overloaded. To extend your example:

package X is
procedure xxx(variable a: out integer); -- a
procedure xxx(variable a: out real); -- a
end;

yes, I use it heavily

BTW is it possible to overload a function on its return type?
(something that can't be done in C++)

Regards, Daniel
 
J

john Doef

Schüle Daniel a écrit :
I think it is more a matter of design
it would be easy to ignore the name the way C does it

int foo(int x);
int foo(int y);
int foo(int); // all the same

hence my question, whether the names are part of subprogram
signature or not.
Yes they are! Cf LRM 2.7
I stumbled over this with names res <-> ret (meaning result <-> return)


By the way,

yes, I use it heavily

BTW is it possible to overload a function on its return type?
(something that can't be done in C++)
Yes it is. LRM 10.5

JD.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top