Search | Synergex.com | Contact Us | Resource Center Login | Home|
News

If a subroutine defines an argument as having type n, and the calling routine passes a literal value of 1 for that argument, what will ^SIZE return for that argument when called within the subroutine?

a. 1
b. 4
c. 4 if prototyped, 1 if not prototyped
d. 4 on 32-bit systems, 8 on 64-bit systems

Discussion:

When a numeric literal is passed as the argument to a routine, Synergy/DE will coerce that value to the type of the argument's declaration as far as possible. Integer values are coerced to the native integer size for the platform, unless a larger size is needed to represent the value. Decimal values receive the minimum length required to store them.

On both 32-bit and 64-bit systems, the native integer size is 32 bits, or 4 bytes. Since the value of 1 does not require more than that, it will never be coerced to 64 bits (8 bytes). Thus, answer (d) is incorrect.

The question then remains whether the value 1 will be coerced to integer (with a size of 4 bytes) or decimal (with a size of 1). Type n means that any numeric value is acceptable. When the compiler knows that the type of the argument is n, it will prefer to coerce literals to integer if possible, for efficiency. Thus, (b) is the ideal answer.

However, what happens if the subroutine is not part of the current compilation? The compiler does not know how the argument is defined. It could just as well be alpha. Prior to the introduction of integer types in Synergy/DE version 5, alpha and decimal arguments were regularly interchanged, because a decimal field represents its value as printable characters. Thus, for compatibility, if the type of the argument is not known at compile time, the compiler coerces numeric literals to decimal (a).

Starting with Synergy/DE version 9, you can inform the compiler about the types of arguments that are declared in source files that aren't part of the current compilation by using the dblproto utility. This utility creates one or more .dbp files to describe the argument signatures of the routines it processes. These can then be imported by the compiler when compiling code that uses those routines, so that the compiler can perform type checks and optimizations on the arguments passed. Thus, the correct answer is (c), if we take the word "prototyped" to mean either “via an imported .dbp file” or “as part of the same compilation.”