U
Ulrich Hobelmann
Hi, since I've done a bit of Java recently, I'm thinking of using some
C++ instead of C, just because the "class" syntax is looking more
convenient now.
One thing that makes me wonder is C++ code size though. I've heard that
C++ is supposed to be just a souped up C that makes you "pay as you go",
and I don't intend to go anywhere far. But a small toy class I wrote
generated much more code than the equivalent C struct, when instantiated
in a test main().
The C code did just what it was supposed to: malloc, fill some struct
fields and return. The C++ code generated two identical (!) constructor
functions that did about what the C one did. The calling code - of
course! - only called one of them, because on the syntax level there was
only one constructor. In addition, some kind of structure was generated
(I assume, the class), even though I don't have anything virtual, and I
don't see where code like I'm planning to write would ever need access
to the class structure.
So my question would be: why are there two constructors when I only
wrote one (even in the final, linked executable)? What/why is the funny
structure in the code? (compiler is GCC/G++ 4.0, but I'm sure 3.x isn't
much different/better)
I'm sure this is something of a FAQ (though Google didn't turn up any
really useful answer), so feel free to direct me to past posts.
Thanks,
Ulrich
C++ instead of C, just because the "class" syntax is looking more
convenient now.
One thing that makes me wonder is C++ code size though. I've heard that
C++ is supposed to be just a souped up C that makes you "pay as you go",
and I don't intend to go anywhere far. But a small toy class I wrote
generated much more code than the equivalent C struct, when instantiated
in a test main().
The C code did just what it was supposed to: malloc, fill some struct
fields and return. The C++ code generated two identical (!) constructor
functions that did about what the C one did. The calling code - of
course! - only called one of them, because on the syntax level there was
only one constructor. In addition, some kind of structure was generated
(I assume, the class), even though I don't have anything virtual, and I
don't see where code like I'm planning to write would ever need access
to the class structure.
So my question would be: why are there two constructors when I only
wrote one (even in the final, linked executable)? What/why is the funny
structure in the code? (compiler is GCC/G++ 4.0, but I'm sure 3.x isn't
much different/better)
I'm sure this is something of a FAQ (though Google didn't turn up any
really useful answer), so feel free to direct me to past posts.
Thanks,
Ulrich