idl2cpp maps global const variable from IDL file differently in VisiBroker for C++ 6.x and 7

idl2cpp maps global const variable from IDL file differently in VisiBroker for C++ 6.x and 7

Problem:

  • Product Name: VisiBroker for C++
  • Product Version: 6.x
  • Product Component: idl2cpp
  • Platform/OS version: All

You have anapplication that is compiled and run smoothly in VisiBroker 6.5 for C++. Aftermigrating to VisiBroker 7.0 for C++, you have encountered following error:

constant value is not known
unsigned int m_value[IDX];

For example

bank.idl will generate bank_c.h, bank_c.cpp, bank_s.h and bank_s.cpp. The IDX will be declared in bank_c.h.

There is another file BigByte.h which will include the bank_c.h and use the IDX by “unsigned int m_value[IDX];".

The IDL is defined with “const long IDX;”. All the files are the same as before but the compiling is getting above problem.

In VisiBroker6.x and previous version, the idl2cpp will map a “const” variable into .h file.For example:

In .idl:

const long IDX=10;
interface Bank{


};

In bank_c.h, it will become:

extern const ::CORBA:Long IDX=10;
class bank {


}

But in VisiBroker 7.0, the code will become:

In bank_c.h:

extern const ::CORBA:Long IDX; //10
class bank {


}

In bank_c.cpp:

const ::CORBA::Long IDX=10;
class bank {


};

If BigByte.h include bank_c.h as before, bank_c.h only contains the declaration of IDX. The actual definitionis in bank_c.cpp. Therefore, when the compiler checks the line “unsignedint m_value[IDX];” in BigByte.h, the compiler will raise error: “unknown const value” or “expected constant expression”. The reason is because the definition is not contained in bank_c.h, but in bank_c.cpp.

In C++, a const that is outside all functions has file scope (i.e., it is invisible outside the file). It defaults to internal linkage. It is very different from all other identifiers in C++ (and from const in C!) that default to external linkage.

Since a const in C++ defaults to internal linkage, you cannot just define a const in one file and reference it as an extern in another file. To give a const external linkage that can be referenced from another file, you must explicitly define it as extern. An example is shown below:

extern const long IDX = 10;

The behaviours of idl2cpp in VisiBroker 6.x and 7.0 are different. Thus, the const defined in bank_c.cpp cannot be used by other file, but only inside bank_c.cpp.

Resolution:

To solve the problem, CR4687 has been filed and fixed in VisiBroker 7.0 Service Pack 2. A new option is added to the idl2cpp compiler to generate the desired code for backward compatibility purposes. Please set "const_in_header" option with the idl2cpp compiler. It only works for global constant defined in IDL. The default for this option is off.

Tags (3)

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 20:08
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.