Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!dayton!viper!john From: john@viper.Lynx.MN.ORG (John Stanley) Newsgroups: comp.sys.atari.st Subject: Re: Megamax WON'T compile .... structures passed to functions Message-ID: <1031@viper.Lynx.MN.ORG> Date: Fri, 22-May-87 01:44:15 EDT Article-I.D.: viper.1031 Posted: Fri May 22 01:44:15 1987 Date-Received: Sat, 23-May-87 14:47:26 EDT References: <280@nikhefh.UUCP> Reply-To: john@viper.UUCP (John Stanley) Organization: DynaSoft Systems Lines: 56 Keywords: megamax In article <280@nikhefh.UUCP> gert@nikhefh.UUCP (Gert Poletiek) writes: > >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! Passing a structure to a function is not supported in the definition of how-C-works... Take a look in your handy dandy K&R (page 121). It tells you that passing structures to a function is -not-supported-. The compilers that have been created since then handle the problem in (unfortunately) one of three incompatable ways... 1) Since K&R said it was not supported, some compilers will flag a structure-parameter as an error... (nuf said, next...) 2) Since passing a structure isn't supported in K&R C, if you include a structure name in a parameter list, you must really mean to pass the address of that structure as a pointer. The compiler thus handles structure and array references in the exact same way. (A few of the compilers that do this (unfortunately, not megamax) go the whole route and also convert a structure receiver on the functions side into a structure pointer and converts structure references within the function into indirect references to match.) Most of the compilers in this class assume you have a struct pointer in the parameter list of the function. If you have a struct instead, the compiler assumes you plan to reference the arguments as a structure for some purpose and the references to the structure elements reference the individual parameters... 3) Some "C" compilers take your word that you do, in fact, want to stick a copy of the entire structure on the stack and pass it to the function. Megamax is aparently one of the class 2 structure passing compilers, but without the (slightly illegal) conversion on the function end of things. Summery: Yes, megamax isn't handling it correctly, but then, you can't count on any program that passes structures to work on any randomly selected C compiler... Apparently you learned to write C on a class 3 compiler. Anything you do that involves passing structures will-not-work on (at a guess) 75% of all compilers. It's a habit you would be better off un-learning as soon as possible. Solution? When you're learning a new compiler or trying to write portable code, make the assumption that passing a struct doesn't work. Pass a pointer to the structure or to a copy of the structure and have a much better chance of your code being portable (and running)... --- John Stanley (john@viper.UUCP) Software Consultant - DynaSoft Systems UUCP: ...{amdahl,ihnp4,rutgers}!{meccts,dayton}!viper!john