[comp.unix.wizards] casting args to functions...

brandon@tdi2.UUCP (Brandon Allbery) (11/11/86)

Expires:


Quoted from <5068@ukme.ukma.uky.csnet> ["Re: Microport Unix -- Large Model Problems"], by david@ukma.uky.csnet (David Herron, NPR Lover)...
+---------------
| In article <840@ur-valhalla.UUCP> dave@valhalla.UUCP (Dave Carlson) writes:
| >A potential problem I smacked into yesterday when porting BSD to SV/AT
| >is ioctl(2) expects as the third argument:
| >union   { int iarg;
| >        char *cparg;}
| >Problem is that the union will pull 4 bytes off the stack (in large model)
| >but the program calling with an integer will only push 2 bytes.  Oh S*$&!
| >I cast my integer args long and everything seems ok but what a pain...
| 
| Argh!  And you're doing a port of an operating system???
| 
| UNIONS are the SAME size regardless of WHICH part of them you use!
| 
| A user which passes an int to a routine expecting a union is ASKING
| for trouble!
+---------------

The problem is not this:  it is that ioctl() is documented as taking a pointer
in some places and as taking an int in others.  Please note that it is not
documented as taking a union, or is the "int" changed to a "long" on machines
with 2-byte integers and 4-byte pointers.  Berkeley int==long-ism strikes
again!

++Brandon
-- 
 /-----------//***/  Brandon S. Allbery		cbosgd!cwruecmp!ncoast!allbery
/---   -----//***/   Tridelta Industries, Inc.  ihnp4!tft2!tdi2!brandon
  /  //---, /---/    7350 Corporate Blvd.      		       !ncoast!allbery
 /  //   / /   /     Mentor, OH 44060
/--//---' /---/      +1 216 255 1080		HOME: +1 216 974 9210

gwyn@brl-smoke.ARPA (Doug Gwyn ) (11/13/86)

In article <115@tdi2.UUCP> brandon@tdi2.UUCP (Brandon Allbery) writes:
>The problem is not this:  it is that ioctl() is documented as taking a pointer
>in some places and as taking an int in others.  Please note that it is not
>documented as taking a union, or is the "int" changed to a "long" on machines
>with 2-byte integers and 4-byte pointers.  Berkeley int==long-ism strikes
>again!

I don't think Berkeley int==long-ism has anything to do with this
specific problem.  If you want to roast Berkeley, how about roasting
them for deciding that those (int)s should be (int *)s and that the
size of the data structures should be encoded into an itty-bitty
field within the ioctl code.