[Info-vax] calloc fails with access violation

Bob Gezelter gezelter at rlgsc.com
Mon Aug 24 16:54:38 EDT 2009


Jose,

Calling cross language requires careful reading of the various
programmer's guides. For historical reasons far beyond OpenVMS, each
language has its preferred mode of passing parameters. There are
OpenVMS-specific ways to override the defaults, and they are generally
documented in the manual entitled "Programmer's Guide" (or similar).

A variable passed "by reference" is passed as an address of the first
byte of the variable (or structure). COBOL and FORTRAN do not zero-
terminate strings, although it is possible that accidental contents of
padding following strings can give an incorrect impression. In both
COBOL and FORTRAN, strings were generally passed to subroutines with
lengths specified also as part of the formal parameters, or implicitly
because of a shared data structure definition.

"C" by contrast, passes scalars by value, and arrays by reference
(strings are in effect, byte arrays). Also, in C the normal convention
for a string is variable length, not fixed length (hence the null
character terminator).

On OpenVMS a descriptor is a structure that contains the address and
length of a storage area. OpenVMS FORTRAN uses descriptors to pass
strings. Much of the OpenVMS library and system services require the
use of descriptors for parameters to system services. The needed
definitions are included in the standard include path in descrip.h
(e.g., "#include <descrip.h>").

A sample piece of code for a C routine passed a descriptor is:

long xyz(struct dsc$descriptor *OutputStructure, struct dsc$descriptor
*InputParameter)
{
      unsigned short int length;
      char *characterstring;

      length = InputParameter->dsc$w_length;
      characterstring = InputParameter->dsc$a_pointer;
......
......

                   }

I do recommend using the above only as a starting point. It is not a
cut-paste, but a transcription from a different window, so I do not
guarantee that there are no typographical errors. My recollection is
that this is documented in the OpenVMS C guide, but in any event, the
descriptor structures are well defined in the include file, and are
also defined in any hardcopy or electronic discussion of the VAX
architecture.

- Bob Gezelter, http://www.rlgsc.com



More information about the Info-vax mailing list