Software Archive
Read-only legacy content
17060 Discussions

Actual parameter analysis between multiple calls to same routine

james1
Beginner
411 Views
The compiler is trying to do an admirable taking care of us when calling a routine more than once in the same compilation pass. When the compiler detects a difference in type of the actual arguments used in calling the same routine, it flags a warning "Routine X called with different number and/or type of actual arguments in earlier call - C attribute required if intended".


While the message is correct, I find it a little overaggressive in its attempt to protect us from ourselves. :-) I have literally thousands of examples summarized by the following short program:



  
program test_init  
character(32) string  
byte array(32)  
call sub (%ref(string))  
call sub (array)  
end  



This program produces the previously mentioned warning for each instance after the first call under CVF, however compiles happily under the latest OVMS compiler.


From what I can tell my solutions are to turn off warnings again or to include an interface definition in each and every caller for said routine(s). Essentially in the case above I would need to add the NO_ARG_CHECK attribute to any such argument subject to this sort of calling procedure (subroutine just wants a byte array in many of these cases, in other words the actual parameter is considered "generic"). As far as I know no type casting is available for the caller to handle it alone.


I guess my case is that, lacking an interface definition, particularly when working with older code, there is something to be said for making NO_ARG_CHECK the default.


James

0 Kudos
3 Replies
Steven_L_Intel1
Employee
411 Views
You get no errors on VMS because character arguments take up only one argument position, a descriptor, whereas on Windows, they take two, an address and a length. When you pass %ref(arg), you're passing only the address. Using the default STDCALL mechanism, there would need to be two different routines as the stack usage would be different. This is why the compiler is complaining.

If you compiled with /iface:cref, then it wouldn't care.

Steve
0 Kudos
james1
Beginner
411 Views
Steve,

On OpenVMS nothing in that sample program is passed by descriptor, note that the character string is explicitly passed by reference and the byte array is passed by reference by default. My understanding is that on both operating systems using the %ref on the character string and using the default mechanism with the byte array should result in a single argument passed by reference in both cases. What am I not understanding?

James
0 Kudos
james1
Beginner
411 Views
I would really like an answer on this one, I keep running into this problem and really think this is a compiler problem. According to the documentation for %REF, the byte array from my example will be passed as a single argument by reference by default. The character argument will be passed "by address and a hidden length" by default, making for two arguments if %REF is NOT used. However if you use %REF on the character actual argument it should then pass that character argument by reference with no hidden length argument, thus making the number of actual arguments the same in both cases. Either the compiler is wrong or the documentation is wrong.

James
0 Kudos
Reply