home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / sys5 / r3 / 198 < prev    next >
Encoding:
Text File  |  1993-01-12  |  1.7 KB  |  71 lines

  1. Newsgroups: comp.unix.sys5.r3
  2. Path: sparky!uunet!mcsun!fuug!kiae!demos!sensor!dnb
  3. From: dnb@sensor.zgrad.su (Dmitri Belosludtsev)
  4. Subject: Re: Compiler wierdness alert...
  5. Organization: Firm "Orgland", Zelenograd, Russia.
  6. Date: Tue, 12 Jan 1993 13:51:41 GMT
  7. Message-ID: <1993Jan12.135141.14137@sensor.zgrad.su>
  8. X-Newsreader: TIN [version 1.1 PL8]
  9. References: <1252@bazooka.amb.org>
  10. Sender: usenet@sensor.zgrad.su (Usenet News Sender)
  11. Lines: 58
  12.  
  13. Ti Kan (ti@bazooka.amb.org) in msg <1252@bazooka.amb.org> writes:
  14.  
  15. > Consider the following program:
  16.  
  17. > ----------------------------------
  18. > #include <stdio.h>
  19.  
  20. > #pragma pack(1)
  21. > union foo {
  22. >     char d1;
  23. >     long d2;
  24. > };
  25. > #pragma pack()
  26.  
  27. > struct bar {
  28. >     char a;
  29. >     char b;
  30. >     char c;
  31. >     union foo d;
  32. > };
  33.  
  34. > main()
  35. > {
  36. >     struct bar x;
  37.  
  38. >     /* display the relative offsets of struct bar members */
  39. >     printf("\t%d %d %d %d\n",
  40. >         (char *) &x.a - (char *) &x,
  41. >         (char *) &x.b - (char *) &x,
  42. >         (char *) &x.c - (char *) &x,
  43. >         (char *) &x.d - (char *) &x);
  44. > }
  45. > ----------------------------------
  46.  
  47. > Program output (Compiled with cc on 3.2v2 DS or or gcc 2.2.2):
  48.  
  49. >     0 1 2 4
  50.  
  51. > Program output (Compiled with cc 3.2v4 DS, or rcc on both 3.2v2 DS
  52. > and 3.2v4 DS):
  53.  
  54. >     0 1 2 3
  55.  
  56. > So, with cc on 3.2v4 or rcc in both versions, the compiler does not put
  57. > a pad byte after field "c" in struct bar, whereas with cc on
  58. > 3.2v2 DS or gcc, it does.
  59. [skipped...]
  60. I tried that programm with ISC Unix ver3.0
  61. gcc (version 1.37.1) results in:
  62.     0 1 2 4
  63. cc (C Software Development System 4.1.5 9/11/91) results in:
  64.     0 1 2 3
  65.  
  66. No comments.
  67. -- 
  68. Dmitri Belosludtsev, Firm "Orgland", Zelenograd, Russia
  69.          e-mail: dnb@sensor.zgrad.su, FIDO: 2:5020/60.6
  70.  
  71.