home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / mac / programm / 14333 < prev    next >
Encoding:
Internet Message Format  |  1992-08-21  |  2.1 KB

  1. Path: sparky!uunet!cs.utexas.edu!swrinde!mips!darwin.sura.net!haven.umd.edu!ni.umd.edu!zben-mac-ii.umd.edu!user
  2. From: zben@ni.umd.edu (Charles B. Cranston)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: byte alignment problem
  5. Message-ID: <zben-210892153814@zben-mac-ii.umd.edu>
  6. Date: 21 Aug 92 19:44:23 GMT
  7. References: <1992Aug17.233739.19308@athena.cs.uga.edu> <John_Shepardson.esh-210892102752@moose.slac.stanford.edu>
  8. Sender: usenet@ni.umd.edu (USENET News System)
  9. Followup-To: comp.sys.mac.programmer
  10. Organization: UM Home for the Terminally Analytical
  11. Lines: 49
  12. Nntp-Posting-Host: zben-mac-ii.umd.edu
  13.  
  14. In article <1992Aug17.233739.19308@athena.cs.uga.edu>,
  15. kinsey@athena.cs.uga.edu (Kevin Kinsey) wrote: 
  16. > a quick question: 
  17. >     if given a struct { char a; long b;} x;, what is the best method
  18. >     to create a buffer that contains 'a' followed by 'b' WITHOUT the
  19. >     implicit padding within the struct.
  20.  
  21. In article <John_Shepardson.esh-210892102752@moose.slac.stanford.edu>,
  22. John_Shepardson.esh@qmail.slac.stanford.edu (John Shepardson) wrote:
  23. > Think C will not add the pad byte within a struct. I can't say about other
  24. > compilers.
  25.  
  26. MPW C will not add pad bytes either.  Guess why the comment in
  27. this data structure, from one of my programs that failed on 68000
  28. hardware:
  29.  
  30. typedef struct {
  31.     DialogRecord dlog;
  32.     short    wtype;
  33.     Rect    wrect;
  34.     Point    ipos;
  35.     WindowPtr    next;
  36.  
  37.     Handle    rhand;
  38.     int        timer;
  39.     int        tcpst;
  40.     int        rhost;
  41.     short    rport;
  42.     short    reason;
  43.     short    dindex;
  44.     char    option;
  45.     char    workf;
  46.     char    openf;
  47.     char    filler;        /* SE/68000 netbuf must be word aligned! */
  48.  
  49.     char    buffer[BUFMAX];
  50.     char    netbuf[NBSIZE];
  51.     struct hostInfo hinfo;
  52. } qwtype, *qwptr;
  53.  
  54. Hint: netbuf is being passed to MacTCP as an 8096 byte connection
  55. buffer, and MacTCP is erecting a custom heap zone in this buffer,
  56. and the heap zone creation code in ROM does a long store into one
  57. of the zone header fields to initialize it.
  58.  
  59. Actually, the only thing suprising is that it all worked fine on
  60. 680x0 x<0 processors even though it was odd-aligned!!!
  61.  
  62. zben@ni.umd.edu     -KA3ZDF
  63.