Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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.

—SA
 
Share this answer
 
v2
Comments
Henry Minute 15-Mar-11 12:35pm    
Good answer, SA.
Sergey Alexandrovich Kryukov 15-Mar-11 12:37pm    
Thank you, Henry.
Hope it resolves the confusion.
--SA
Dalek Dave 16-Mar-11 4:45am    
Good Call.
Sergey Alexandrovich Kryukov 16-Mar-11 4:59am    
Thank you.
Hope it... oh, I already said that :-)
--SA
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?
 
Share this answer
 
v2
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900