delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/02/12:02:04

Newsgroups: comp.os.msdos.djgpp
From: Peter Berdeklis <peter AT atmosp DOT physics DOT utoronto DOT ca>
Subject: Re: complex numbers, correct ??
Message-ID: <Pine.SGI.3.91.970902103054.29054C-100000@atmosp.physics.utoronto.ca>
Nntp-Posting-Host: chinook.physics.utoronto.ca
Sender: news AT info DOT physics DOT utoronto DOT ca (System Administrator)
Mime-Version: 1.0
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> <Pine DOT SGI DOT 3 DOT 91 DOT 970827160403 DOT 12574A-100000 AT atmosp DOT physics DOT utoronto DOT ca> <3406B175 DOT 35AB AT rug DOT ac DOT be> <Pine DOT SGI DOT 3 DOT 91 DOT 970829111941 DOT 7949B-100000 AT atmosp DOT physics DOT utoronto DOT ca> <340799A6 DOT 1F1F2BEB AT alcyone DOT com>
Lines: 30
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019