Path: utzoo!mnetor!uunet!husc6!bloom-beacon!athena.mit.edu!newman From: newman@athena.mit.edu (Ron Newman) Newsgroups: comp.windows.x Subject: Re: X11 inconsistency question Message-ID: <2059@bloom-beacon.MIT.EDU> Date: 18 Dec 87 18:23:44 GMT References: <8712180210.AA29937@ATHENA.MIT.EDU> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: newman@athena.mit.edu (Ron Newman) Organization: Massachusetts Institute of Technology Lines: 36 In article <8712180210.AA29937@ATHENA.MIT.EDU> marshall@software.ORG (Eric Marshall) writes: > > Why is it that the components of the XPoint struct are >shorts, the x and y values taken as parameters to Xlib calls are >int's, and the height and width taken by Xlib calls are unsigned >ints (especially why unsigned)? Why is there not a single object >type to reflect the display size? Thanks in advance. > The components of the XPoint structure are signed shorts because most compilers treat shorts as 16-bit entities, and the protocol representation of a POINT is [x, y: INT16], i.e. two 16-bit signed integers. Since a client program may pass a large number of XPoints to XDrawPoints, Xlib wants to put the client's data directly on the wire, without having to reformat it from (possibly 32-bit) "int" to 16-bit "short". For similar reasons, the "x" and "y" components of XSegment, XRectangle, and XArc are declared to be signed shorts. The "width" and "height" components of XRectangle and XArc are declared as unsigned shorts because the protocol declares them to be CARD16, which for most C compilers is an unsigned short. The "x" and "y" arguments to Xlib calls are "int"s because (a) they are signed values, and (b) there would be no point in declaring them to be shorts, since the C language would treat promote them ints anyway. The "height" and "width" arguments to Xlib calls are "unsigned int"s because the protocol specifies them to be CARD16, i.e. 16-bit unsigned integers. If the parameters were declared as "int" on a machine with 16-bit "int"s, you would lose the ability to use values between 32768 and 65535. /Ron Newman (one of the Xlib implementors)