Click here to Skip to main content
13,148,260 members (58,134 online)
Rate this:
Please Sign up or sign in to vote.
See more:
The structures declared in IDL file cannot have constructors. So, how does programmer ensure that corresponding user object is properly initialized and does not have junk value for any of its members, at runtime?
Posted 15-Mar-11 3:36am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Your question is simply not applicable to IDL. It is applicable to implementation of the functions defined by IDL.

IDL is "Interface Definition Language". When you compile it, you got interfaces only (well, just a bit more). When you generate source code in some languages you will get interfaces or declarations equivalent to interfaces. For C++, for example, the classes are generated, but they produce exact same binary layout required by COM interfaces. More exactly, interfaces are expressed as classes with no data with all members being pure virtual function.

When you write the code based on your IDL, it's your responsibility to write implementation for these interfaces. For example, in case of C++ you create a class and make one or more interface classes your base classes. You implement the interface(s) by overriding each and every pure virtual function. Everything else depends in the implementation of those overridden interface functions. If you have data which need initialization, take care about it.

Henry Minute 15-Mar-11 12:35pm
Good answer, SA.
SAKryukov 15-Mar-11 12:37pm
Thank you, Henry.
Hope it resolves the confusion.
Dalek Dave 16-Mar-11 4:45am
Good Call.
SAKryukov 16-Mar-11 4:59am
Thank you.
Hope it... oh, I already said that :-)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I think I did not pose the problem correctly. The implementation of interfaces by co-class is well-known. The co-class can initialize itself and its method implementation can validate interface inputs etc. However, I am talking of structure data types in IDL which are used in interface methods. e.g.

Interface I{
typedef struct S{
     data_type1 m1;
     data_type2 m2;
HRESULT Method([in] S s, [out]IObject *pObject);

The structure S is not available with me in C++ header/source files.
It cannot have constructor. Hence, when user creates an instance of S, and uses the interface method I::Method, the I::Method cannot be sure of what all members of S have been initialized by the user and what have not been?
The unitilized members of instance of S can have junk values which I::Method cannot understand? The programmer's problem is how to provide default initialiation of S?
Dalek Dave 16-Mar-11 4:46am
I edited for the code block, but a good answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170924.2 | Last Updated 16 Mar 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100