Determining the size of an array passed as an argument in Synergy/DE
Sterling Camden
When an array is passed to a function or subroutine in Synergy/DE, the number of dimensions must be declared in the subroutine — but the size of each dimension may not be specified. Not knowing where the edge of a dimension lies can easily lead you to step off the garden path and over the cliff known as “Segmentation violation”. Let’s not go there.
Synergy/DE version 9 adds a handy function, ^argdim, that lets you obtain the size of an array dimension. You pass it the argument number (starting at 1 — you can use ^argnum(name) to obtain that if you don’t feel like counting) and the dimension number (again, starting at 1 for the left-most dimension), and it returns the number of elements in that dimension.
If you’re still stuck on a pre-9 version of Synergy/DE, do not despair. The downloadable code below contains a function, %get_dim (in getdim.dbl), which does the same thing (except you pass it the argument name instead of the number). Get_dim achieves this magic by declaring the array parameter as a ^val address of a descriptor. When an argument is normally passed to a function, what really gets placed on the stack is a pointer to a descriptor that, um, describes the argument. The descriptor contains information about type, size, address of the data itself, and several other things including dimension information. If you look at the code you’ll probably notice that the dimension info is not all that straightforward. For one thing, on OpenVMS Synergy/DE uses a native descriptor, so the information is stored completely differently than on other platforms. That difference is conditionally compiled in the function, which works on UNIX, Windows, and OpenVMS.
The other file included, tdim.dbl, is a test routine for our function. It also uses conditional compilation to employ ^argdim if we’re on version 9 or later, and %get_dim otherwise. If you’re planning to use this in production code that’s cross-version, I would recommend putting that .ifdef block into an include file, and using the macro instead of calling %get_dim or ^argdim directly.
Posted in OpenVMS, SynergyDE, Unix, Windows |
No Comments » RSS 2.0 | Sphere it!




