Problem:
- Product Name: Visibroker
- Product Version: 6.0 and later
- Product Component: idl2cpp
- Platform/OS Version: All
After upgrading to VBE 6.0 SP7 from VBE 6.0, the source code does not compile. The same problem also happens in VBE 6.5.
Previously, for an IDL containing this:
const short PkValid = 1;
const short PkInvalid = 0;
const short PkFatal = -1;
the code generated by idl2cpp looked like this:
const ::CORBA::Short PkValid = 1;
const ::CORBA::Short PkInvalid = 0;
const ::CORBA::Short PkFatal = -1;
which allowed the developer's code to directly use the values in case statements
Now with patch 7, the generated code looks like:
PkErrorIF_CLASS extern const ::CORBA::Short PkValid; // 1
PkErrorIF_CLASS extern const ::CORBA::Short PkInvalid; // 0
PkErrorIF_CLASS extern const ::CORBA::Short PkFatal; // -1
This resulted in compilation errors like the following:
Example 1:
RecvSortDriver.cpp:114: case label does not reduce to an integer constant
The code is
112) switch (pkerror)
113) {
114) case PkValid:
Example 2:
CreateCCTaskClient.cpp:133: undefined reference to `PkValid"
The Code is
if (getLoginObject(loginObj, userId) != PkValid)
This problem originated in VBE 6.0 SP4 while trying to address some issues regarding the IDL constants not exported properly from the DLL in Windows platform. The idl2cpp compiler in VBE 6.0 SP4 moves the definition of the IDL constants from the *_c.h file (the stub header file) to the *_c.Cxx file. The *_c.h file only contains the constant declaration now.
Since the definition is not in the header file, these constants become run time constants. Hence they cannot be used with the C/C switch statements, which requires constants known at the compile time. This breaks the source compatibility.
Resolution:
To use the IDL defined constant in the switch/case statement, please add the new "-const_in_header" option to the idl2cpp compiler. This works for global constants defined in IDL only. The default for this option is off.
This "-const_in_header" option is available in the latest Service Pack of VisiBroker 6.5, 7.0, 8.0 and G.A version of 8.5.
In VBE 6.0, you may use the "vbcdev.jar" from VBC 6.0 base release as a workaround.
#idl2cpp
#Security
#VisiBroker




