From: utzoo!decvax!genradbo!mitccc!zrm Newsgroups: net.unix-wizards Title: Re: Information on Unix/Vax peculiarities Article-I.D.: mitccc.198 Posted: Sun Nov 28 14:42:41 1982 Received: Mon Nov 29 02:25:24 1982 References: sri-unix.4448 Well, it would take too long to list all the possible machine dependencies possible with C compiler instantiations, but perhaps some general philosophy of C might help. o In general, you want to be able to cast *anything* to int. This means an int ought to be the same size as a pointer. Berkley, and Whitesmith's do this correctly in their compilers, Alcyon does it wrong. o Muddling about inside larger objects should be done with unions. However, in the program CHUQUI mentioned, the author seems to have been ingenious enough to scuttle all portability -- he probably assumes ints hold exactly two bytes. Note that using unions also insures tha byte ordering within a larger word won't matter from machine to machine (assuming the compiler isn't broken). There is also a rather rude hack you can use where you declare and array struct { char hibyte; char lobyte; } and use the members of that structure to reference parts of a two-byte object with the syntax WORD foo; /* WORD is a defined type, another very useful tool */ high = foo.hibyte; /* BLETCH! */ but this is really horrid style and would rather use RPGII than actually maintain code like that. o A fix that might work for CHUQUI is using defined types. But you have to be very careful on several counts. > If you substitute, say, WORD for int, on a wholesale basis, you have to make sure no pointers are being put in ints. > All parameters passed to functions are of size sizeof(int). Treat parameters essentially as you would registers. All this is making me queasy. There are all sorts of other nasty little things you can trip over on your way from one machine (or compiler) to the next and the ony way to verify portability is to port something and fix it when it breaks. Indigestion! Zig