Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!im4u!ut-sally!ut-ngp!infotel!pollux!megamax!peter From: peter@megamax.UUCP Newsgroups: comp.sys.atari.st Subject: Re: Megamax WON'T compile .... structures passed to functions Message-ID: <754@megamax.UUCP> Date: Wed, 27-May-87 13:31:56 EDT Article-I.D.: megamax.754 Posted: Wed May 27 13:31:56 1987 Date-Received: Fri, 29-May-87 04:46:31 EDT References: <280@nikhefh.UUCP> Reply-To: peter@megamax.UUCP (Peter Taliancich) Organization: Megamax, Inc; Dallas, TX Lines: 123 Keywords: megamax > > In response to the denial of a few persons that Megamax won't accept > passing of structures to functions: The Megamax compiler will accept the C > code. It will not issue any warning, but the code it generates it > totally wrong! > > > Megamax disassembler V1.0, Copyright (C) 1986 by Megamax Inc. > > CODE SEG "main" > main:/* global */ > LINK A6,L$0 > PEA -4(A6) !!! here main pushes the ADDRESS of the structure > test, when it should push the contents of it. > JSR ftest(PC) > ADDQ.L #4,A7 > L1: > UNLK A6 > RTS > L$0: .EQU #-4 > _initargcv:/* global */ > RTS > ftest:/* global */ > LINK A6,L$2 > MOVE #1,8(A6) !!! this would be t.t1 = 1, the ftest function > apparantly expects the structure to be on > stack, unfortunately only the address of the > structure is on the stack. (Bomb!!) > MOVE #2,10(A6) > L3: > UNLK A6 > RTS > L$2: .EQU #0 > > > > This example was compiled with version 1.1 of the Megamax compiler. > I hope this makes clear that Megamax does not 'allow' structure passing. > > Gert Poletiek. Structure passing and assignment have been a part of the Megamax C language since the very first day on the Atari. The code that was generated by the compiler using the example program that was sent is as follows: This is the test program: typedef struct { int t1; int t2; } test; extern test ftest(); main() { test test; ftest(test); } ftest(t) test t; { t.t1 = 1; t.t2 = 2; return t; } This is the disassembled object module: CODE SEG "main" main: /* global */ LINK A6,L$0 LEA -4(A6),A1 SUBA #4,A7 MOVE.L A7,A0 MOVEQ #1,D0 JSR _blockmv(PC) <-- place structure onto the stack JSR ftest(PC) <-- do structure thing ADDQ.L #4,A7 LEA -4(A6),A0 MOVEQ #1,D0 JSR _blockmv(PC) <-- assign struct with returned struct from function L1: UNLK A6 RTS L$0: .EQU #-4 BSS SEG "bss" 1struct: .WORD #4 <-- hold place for returned structure CODE SEG "main" ftest: /* global */ LINK A6,L$2 MOVE #1,8(A6) <-- access members of structure on the stack MOVE #2,10(A6) LEA 8(A6),A1 LEA 1struct(A4),A0 MOVEQ #1,D0 JSR _blockmv(PC) <-- hold place for returning structure LEA 1struct(A4),A1 UNLK A6 RTS L$2: .EQU #0 This source file was compiled with Megamax C v1.1. Even though it is generally not good practice to depend on structure passing with other C systems the Megamax system definitely supports it. If your Megamax C compiler doesn't seem to generate the proper code, send in your disks. The upgrade to version 1.1 of the Megamax Development System is free (please send Self Addressed and Stamped Disk Mailer.)