Mail Archives: djgpp/1997/09/02/12:02:04
On Fri, 29 Aug 1997, Erik Max Francis wrote:
> Peter Berdeklis wrote:
>
> > Since no second argument is passed, the next thing that printf should
> > print is complete garbage.
>
> What is likely happening is that the complex data type has its first two
> members two doubles. Since it's being passed by value, those two
> doubles (and whatever else, if anything -- probably not with a complex
> number) is being pushed on the stack. The printf, following the
> instructions in the format specifier, pops two doubles off the stack and
> prints them.
>
> This is a "lucky accident";...
I agree completely that this may work, and in the form that you describe.
But as you said it is a lucky accident that is bound to break. Add a
virtual function to the class or a subclass, perhaps to provide prettier
printing for example, and the vtable pointer goes to the front of the
structure and everything goes boom.
Since it might work by lucky accident, perhaps I was overzealous in
saying that any compiler on which the code works is buggy. I therefore
apologize to all compiler vendors who read this newsgroup/mailing list,
knowing that gcc/DJGPP kicks butt. :)
---------------
Peter Berdeklis
Dept. of Physics, Univ. of Toronto
- Raw text -