|
|
|
|||||
|
Using Ice 3.2.0 on Linux RH3 and GCC 3.3.5, I've run into a problem related to the lack of member initialization in default constructors generated by the slice2cpp compiler. Attached is the test program; search for TODO to see what makes the test case succeed. Without explicit member initialization, the program throws the exception in AImpl::dispose() and valgrind says the following:
... Conditional jump or move depends on uninitialised value(s) ... I'm not sure if this is a GCC compiler issue or not, but explicitly initializing the primitive member 'A::mFlags' solves the problem for me. I have not tried to reproduce the problem with another compiler. |
|
|||||
|
Not a bug, just a request for enhancement
On closer examination it is obvious why the exception is thrown. The same memory region is being used for both objects and so the flag will be set unless the member is initialized to 0. I apologize for filing this as a bug.
It might be useful to have an option in slice2cpp that would initialize all members, including those of built-in types, in the default constructor of a class. I have an example where I must pass many arguments to a class constructor, only one of which is really required to initialize a member of type Code:
::Ice::Long Matthias |
|
|||||
|
Using factories to initialize members selectively
Thanks for the response and advice, I'm basically doing what you suggest. The performance argument is a good one too, especially for aggregate members. Nonetheless, if an option were available in slice to annotate classes so their primitive members would be initialized by the default constructor (e.g. as they are in Java), I would use it.
On a related note, I noticed that the generated constructor taking arguments to initialize all members has an initializer list which repeats the initialization of all inherited state at every level in the inhertiance hierarchy. Is this to guarantee a certain order of initialization? Matthias |
|
||||||
|
Quote:
Brent |
|
||||||
|
Quote:
Of course, Ice does contain a number of convenience functions. But, when it does, they are for things that most developers want to do often (as opposed to things that a few developers want to do rarely). In other words, if demand for a convenience feature is big, that sometimes warrants adding the feature. The fundamental design tradeoff here is whether the added complexity for everyone is worth the added convenience for some developers. One of the appealing things of Ice is that it is simple and easy to learn and that, almost always, developers don't pay for what they don't use. Every feature we add makes APIs bigger and requires extra documentation. The documentation issue is serious because, usually, the extra feature means that the developer has to wade through more text about a topic to find what he or she needs, which adds extra friction. (Even if a feature is invisible at the API level (or Slice level) until it is needed, it becomes visible in the documentation.) You might want to read my recent article on API Design for more thoughts on the matter. Quote:
Cheers, Michi. |
|
|||||
|
Thanks
Brent and Michi
I appreciate the detailed response and understand where you're coming from regarding extensions to ICE/slice. No problem. Thank you also for clarifying the initialization of virtual bases. Cheers and have a good weekend. Matthias |
|
||||||
|
Quote:
The reason Ice generates virtual inheritance for bases is so that you can use Slice class in multiple implementation inheritance without ending up with multiple copies of a base. Cheers, Michi. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Call to a member function GetID() on a non-object | rama | Help Center | 0 | 12-15-2006 10:12 AM |
| member ambiguity error when creating a smart pointer | heathbar | Help Center | 3 | 04-09-2006 06:32 PM |
| derived constructor generation bug in slice2cpp | bpolivka | Bug Reports | 3 | 03-02-2006 10:42 AM |
| Identity Constructor | acbell | Comments | 1 | 08-30-2005 02:34 PM |
| Constructor and Default-Parameter | Mr.Freeze | Help Center | 1 | 08-13-2003 08:07 AM |