Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!helios.ee.lbl.gov!ux5.lbl.gov!beard From: beard@ux5.lbl.gov (Patrick C Beard) Newsgroups: comp.sys.mac.programmer Subject: Re: passing correct var size in MPW C/C++ Message-ID: <6280@helios.ee.lbl.gov> Date: 25 Jul 90 19:26:49 GMT References: <26ACA0CB.542F@wilbur.coyote.trw.com> <43315@apple.Apple.COM> <1990Jul24.235007.20545@laguna.ccsf.caltech.edu> Sender: usenet@helios.ee.lbl.gov Reply-To: beard@ux5.lbl.gov (Patrick C Beard) Distribution: usa Organization: Berkeley Systems, Inc. Lines: 30 X-Local-Date: 25 Jul 90 12:26:49 PDT In article <1990Jul24.235007.20545@laguna.ccsf.caltech.edu> chi@tybalt.caltech.edu (Curt Hagenlocher) writes: #In article <43315@apple.Apple.COM> marc@Apple.COM (Mark Dawson) writes: #>I wrote a routine in assembly that I wanted to call from my C++ code, it #>didn't end up working the way I expected--the C++ call kept passing a long, #>when my assembly was expecting a short (2 bytes). I've of course modifed #>my assembly to expect a long, but I'd like to know where my thinking went #>wrong. #> # #MPW C always converts everything to 32 bits that's less than #32 bits in length. This includes characters and shorts. #The information is put into the low (byte/word) and sign extended #to make a long integer. This is correct. For all routines that use C calling conventions, all types are pushed as 32-bit quantities. One way to use smaller size parameters is to declare a routine with "pascal" calling conventions. So, if you really only want to push a word, declare your routine as: extern pascal void MyRoutine(short arg); And C++, or C will only push a 2-byte integer on the stack. -- ------------------------------------------------------------------------------- - Patrick Beard, Macintosh Programmer (beard@lbl.gov) - - Berkeley Systems, Inc. "..............Good day!" - Paul Harvey - -------------------------------------------------------------------------------