Newsgroups: comp.os.msdos.djgpp From: Peter Berdeklis Subject: Re: complex numbers, correct ?? Message-ID: Nntp-Posting-Host: chinook.physics.utoronto.ca Sender: news AT info DOT physics DOT utoronto DOT ca (System Administrator) Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Organization: University of Toronto - Dept. of Physics In-Reply-To: <340799A6.1F1F2BEB@alcyone.com> Date: Tue, 2 Sep 1997 14:36:04 GMT References: <5tsl8i$ce$1 AT news DOT IAEhv DOT nl> <3406B175 DOT 35AB AT rug DOT ac DOT be> <340799A6 DOT 1F1F2BEB AT alcyone DOT com> Lines: 30 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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