slh@wolf.cs.washington.edu (Scott Heyano) (11/24/90)
In article <1990Nov23.231941.14801@thyme.jpl.nasa.gov> kaleb@thyme.jpl.nasa.gov (Kaleb Keithley ) writes: ||In article <2450@kiwi.mpr.ca> baker@mprgate.mpr.ca (Sue Baker) writes: || DAMNIT, you can only pass the POINTER TO THE STRUCTURE, || NOT the actual structure. || So only the first 32-bits are passed, in this case | |No, I don't think so. K&R1 says you can. Just because you might |not ordinarily want to. Just because in this case it is definitely |wrong. Doesn't make it *always* wrong. No, not C won't let you do it, but Xt won't let you do it. The parameter must be of type caddr_t, usually 32-bits. I got a little annoyed because someone else asked essentially the same question here just recently. By the way, I think you missed a level of quoting on your quote attribution.
fjb@metaware.metaware.com (Fred Bourgeois) (11/28/90)
In article <13840@june.cs.washington.edu> slh@wolf.cs.washington.edu (Scott Heyano) writes: >In article <1990Nov23.231941.14801@thyme.jpl.nasa.gov> kaleb@thyme.jpl.nasa.gov (Kaleb Keithley ) writes: >||In article <2450@kiwi.mpr.ca> baker@mprgate.mpr.ca (Sue Baker) writes: >|| DAMNIT, you can only pass the POINTER TO THE STRUCTURE, >|| NOT the actual structure. >|| So only the first 32-bits are passed, in this case >|No, I don't think so. K&R1 says you can. Just because you might >|not ordinarily want to. Just because in this case it is definitely >|wrong. Doesn't make it *always* wrong. I seem to have missed the original article, but ANSI C does allow structs (not just struct *s) as arguments to functions. If your compiler doesn't handle this, its broken. If curious, try the code below, which should demonstrate passing (and returning) structs from functions. ----- #include <stdio.h> typedef struct{float x;short a;long b;double y;char c;}Bar; static Bar foo(Bar z) { Bar q = { 2.1828, 256, 2147483647, 3.1415926535, 'z' }; return z = q; } static void foobar(Bar none) { printf("\tfloat x: %#f\n", none.x); printf("\tshort a: %d\n", none.a); printf("\tlong b: %ld\n", none.b); printf("\tdouble y: %#e\n", none.y); printf("\tchar c: %c\n", none.c); } main() { Bar xyzzy = { 0.0, 0, 0, 0.0, 'a' }, zzyzx; puts("before calling foo, xyzzy struct contains:"); foobar(xyzzy); zzyzx = foo(xyzzy); puts("\nafter calling foo, xyzzy struct contains:"); foobar(xyzzy); puts("\nAnd zzyzx struct contains:"); foobar(zzyzx); } ----- --- Fred Bourgeois, MetaWare Inc., 2161 Delaware Avenue, Santa Cruz, CA 95060-2806 fjb@metaware.com ...!uunet!metaware!fjb Colorless Green Ideas Sleep Furiously, and so do I.