Was this helpful?
Coding C Procedures
Use the following format when coding a C procedure:
procname([parameters])
{
  processing statements 
}
In C, the procedure must not be named "main," and it must not be static. You can call any other C procedure from 4GL.
In C, observe these passing modes:
Pass an integer as four bytes by value (or by pointer, if byref is specified).
Pass a float as a double-format float by value (or by pointer, if byref is specified).
Pass a string as a pointer to a null-terminated string.
Pass fixed-length string types (c, char) with trailing blanks up to their full length.
Pass variable-length string types (text, varchar) without trailing blanks.
Consider this call to a procedure q:
callproc q (1 + 2, 2.3, 'This is a string');
The following declarations are required:
q(x, y, z)
long x;
double y;
char *z;
{
  processing statements 
}
To pass x and y by reference, make the following changes to their formal argument declarations:
long *x;
double *y;
No changes are necessary to pass z by reference.
A C procedure must return an int, a double, or a char * value, as shown below.
To return an integer:
int
reti()
{
  return 10;
}
To return a floating-point value:
double
retf()
{
  return 10.5;
}
To return a character string:
char *
rets()
{
  return "Returned from rets";
}
Any C procedure that returns a char * value to 4GL must return a pointer to a valid address (a string constant or static or global character buffer). The procedure cannot return a pointer to a local character buffer.
Last modified date: 01/30/2023