72
C/C++ Applications on z/OS and OS/390 UNIX
to 7.1.3, ANSIALIAS compiler option on page 95 for an explanation of
this option. Example:
$ c89 -Wc,NOANSIALAS
4.6.2 Enum size
On most other UNIX platforms, the size of enum is constant and is usually the size of int. On
z/OS, the size of enum depends on the range of the enumerators (enum constants). The
compiler uses the size of the smallest integral type for the enumthe size could be 1, 2 or 4
bytes.
This usually does not present a problem unless the enum is used inside a structure. To force
the enum to be of size int, insert an enumeration constant with value INT_MAX.
An option, ENUM, is provided in V2R9 via a PTF (and available starting in OS/390 V2R10) to
control the enum size. However, this option must be used with care as it affects all enums
including those defined in system headers. Enums defined in system headers must remain
the same size, otherwise the behavior is undefined. Refer to the OS/390 C/C++ Compiler
User Guide, Chapter 5, Compiler Options.
4.6.3 Extern C
The parameter passing convention for function calls (i.e., the linkage convention) is different
between C and C++ on z/OS. If you are mixing C and C++ source code, make sure you use
the extern C construct to specify C functions. For example:
extern C {
void foo(int);
}
or
extern C void foo(int);
or
void __cdecl foo(int);
For function pointers, the syntax is a bit tricky. Keep in mind that a qualifier always qualifies
the * before it. For example:
void (* __cdecl F)(int);
Read the declaration starting from the name:
F is a __cdecl pointer
to a function
with an int parameter
returning void.
You can use F to point to the function foo defined earlier:
F=&foo;
Hints
You can write function pointer declarations using the following steps:
1. Ignore the pointer first. Just write down the function prototype; for example, void* foo (int,
int*) is a function taking two parameters, int and int*, and returns a void*. In this case, foo
is just a dummy name.