Path: utzoo!attcan!uunet!tektronix!tekcrl!tekgvs!larryh From: larryh@tekgvs.TEK.COM (Larry Hutchinson) Newsgroups: comp.sys.mac.programmer Subject: That amazing MPW C compiler. Keywords: MPW C bug Message-ID: <3428@tekgvs.TEK.COM> Date: 11 May 88 15:16:49 GMT Organization: Tektronix Inc., Beaverton, Or. Lines: 47 I recently happened upon an amusing little feaure/bug of the MPW C compiler. In the little routine below, the compiler actually did what I wanted and NOT what I told it to do! The relevant code is the 'if' statment. You will note that if the first part of the 'if' is true then cTop will be loaded with the undefined value in tmp. What is actually used is the result from the (xxx*8/10) which was calculated in register d0. This is exactly what I intended and the code worked just fine. The code had been working for months and I found it only because I wanted to change something and couldn't figure out how it worked! Since cTop IS loaded with tmp if something is assigned to tmp before the 'if' statment, I assume that this action is the result of a conscious decision on the part of the compiler writer. /* * Autosize thewin in the lower portion of useable. * Window top is not moved if it is in the lower 20% of * useable. */ void SetCWinPos(thewin,useable) WindowPtr thewin; Rect *useable; /* screen space for windows */ { int cTop; /* top of the c window */ int tmp; cTop= -thewin->portBits.bounds.top; if( (cTop < (useable->bottom*8)/10) || (cTop > (tmp= (useable->bottom-MINCMD_VSIZE))) ) cTop= tmp; MoveWindow(thewin,useable->left,cTop,0); SizeWindow(thewin, useable->right-useable->left,useable->bottom-cTop, -1); } Larry Hutchinson, Tektronix, Inc. PO Box 500, MS 50-383, Beaverton, OR 97077 UUCP: [uunet|ucbvax|decvax|ihnp4|hplabs]!tektronix!tekgvs!larryh ARPA: larryh%tekgvs.TEK.COM@RELAY.CS.NET CSNet: larryh@tekgvs.TEK.COM