home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1250 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  20.4 KB

  1. From: Steve.Bleazard@Robobar.Co.Uk
  2. Newsgroups: comp.unix.xenix,alt.sources
  3. Subject: Xenix 386 GCC: an interim patch.
  4. Message-ID: <1990May1.172424.9185@robobar.co.uk>
  5. Date: 1 May 90 17:24:24 GMT
  6.  
  7. [ If you're looking for the archive sub-headers, there aren't any.
  8.   Wait for the complete patch kit if you need them :-) ]
  9.  
  10. Here are some enhancements to my port of GCC to Xenix.  A complete patch
  11. kit relative to the original GNU distribution will be posted to
  12. comp.sources.misc soon.  This patch kit is for those of you who have
  13. already installed my other kits and want to upgrade NOW.  This will
  14. bring you almost to the same release level as binary kits I distribute marked
  15. 1.37.1c <-- note the 'c'.
  16.  
  17. *** ../gcc-1.37.old/c-parse.y    Wed Jan 17 06:13:26 1990
  18. --- ./c-parse.y    Tue Apr 24 11:07:55 1990
  19. ***************
  20. *** 1783,1788 ****
  21. --- 1783,1829 ----
  22.             && getc (finput) == 'm'
  23.             && getc (finput) == 'a'
  24.             && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
  25. + #ifdef PRAGMA_PACK
  26. +       {
  27. +         token = yylex();
  28. +             if (token != IDENTIFIER) 
  29. +             goto skipline;
  30. +             if (strcmp(token_buffer, "pack") != 0)
  31. +                 goto skipline;
  32. +         
  33. +         token = yylex();
  34. +           if (token != '(') {
  35. +             error ("invalid #pragma pack expecting '('");
  36. +             goto skipline;
  37. +         }
  38. +         /* setup default alignment first */
  39. +         pragma_pack_default();
  40. +         token = yylex();
  41. +         if (token != ')')
  42. +         {
  43. +             if (token == CONSTANT
  44. +                 && TREE_CODE (yylval.ttype) == INTEGER_CST) {
  45. +                 int l = TREE_INT_CST_LOW (yylval.ttype);
  46. +                 pragma_pack(l);
  47. +             }
  48. +             else {
  49. +                 error ("invalid #pragma pack expecting 1, 2 or 4");
  50. +                 goto skipline;
  51. +             }
  52. +             token = yylex();
  53. +         }
  54. +           if (token != ')') {
  55. +             error ("invalid #pragma pack expecting ')'");
  56. +             goto skipline;
  57. +         }
  58. +         }
  59. + #endif
  60.           goto skipline;
  61.       }
  62.   
  63. *** ../gcc-1.37.old/Changes.Xenix    Thu Jan  1 00:00:00 1970
  64. --- ./Changes.Xenix    Mon Apr 30 20:57:14 1990
  65. ***************
  66. *** 0 ****
  67. --- 1,52 ----
  68. + Here are some enhancements to my port of GCC to Xenix.  A complete patch
  69. + kit relative to the original GNU distribution will be posted to
  70. + comp.sources.misc soon.  This patch kit is for those of you who have
  71. + already installed my other kits and want to upgrade NOW.  This will
  72. + bring you almost to the same release level as binary kits I distribute marked
  73. + 1.37.1c <-- note the 'c'.
  74. +         o  made TARGET_DEFAULT 1, which implies default -m80387.
  75. +         o  fixed gcc -p to make the result compatible with Microsoft's
  76. +            profiling support.  Results largely untested by me.
  77. +         o  fixed linker specification to handle -s -r -u and -F
  78. +            (the last is ignored by ld, but is useful so as not to break
  79. +             existing Makefiles)
  80. +         o  added optional support for Microsoft's #pragma pack()
  81. +            hack.  This enables people compile GNU Make, my ranlib(CP) and
  82. +            Ron Kuris's GDB port with GCC.  This is switched on by default,
  83. +            but can be disabled by removing #define PRAGMA_PACK from
  84. +            tm-xenix386.h.  This modification will in any case not take effect
  85. +            until the first #pragma pack() is seen in any one source file.
  86. +            A program to test this "feature" called  packtest.c is included
  87. +            Check its leading comment for instructions.
  88. +            When compiled in, it will identify its presence in the cc1 -version
  89. +            output string.
  90. +         o  undefined PCC_BITFIELD_TYPE_MATTERS because I *suspect* that
  91. +            it may interfere with #pragma pack() and its behaviour was not
  92. +            compatible with MSC in the first place.  It still isn't
  93. +            (when your structures have bitfields in them).
  94. +            I think this means that if you need Microsoft binary
  95. +            compatibility, you will have to edit your .h files to put
  96. +            explicit padding into structs that have bitfields where Microsoft
  97. +            seems to do so by default.  Or you could hack stor-layout.c :-)
  98. +         o  removed stddef.h hack -- moved into Makefile.  This is needed for
  99. +            the item immediately below.  Please remove -D_SIZE_T when
  100. +            compiling GCC with GCC, e.g. by following our original instructions.
  101. +         o  Ronald's hack of a include file fixer included (fix.h.xenix).
  102. +            Running it with the -all flag will allow you to compile gcc with
  103. +            gcc without the -traditional flag (if you already have a working
  104. +            gcc, or for the stage2 build) READ IT FIRST, because it's only
  105. +            likely to work for you out of the packet if your include files
  106. +            look exactly like ours.
  107. +         o  ASM_SPEC in tm-xenix386.h: pass -v flag to gas from gcc.
  108. +         o  Enabled production of DBX debugging information for future use.
  109. *** ../gcc-1.37.old/Makefile    Tue Apr 24 00:34:17 1990
  110. --- ./Makefile    Tue Apr 24 11:08:03 1990
  111. ***************
  112. *** 21,27 ****
  113.   # Variables that exist for you to override.
  114.   # See below for how to change them for certain systems.
  115.   
  116. ! CFLAGS = -g $(XCFLAGS)
  117.   CC = cc
  118.   BISON = bison
  119.   BISONFLAGS = -v
  120. --- 21,27 ----
  121.   # Variables that exist for you to override.
  122.   # See below for how to change them for certain systems.
  123.   
  124. ! CFLAGS = -g $(XCFLAGS) -D_SIZE_T
  125.   CC = cc
  126.   BISON = bison
  127.   BISONFLAGS = -v
  128. ***************
  129. *** 28,34 ****
  130.   AR = ar
  131.   SHELL = /bin/sh
  132.   # on sysV, define this as cp.
  133. ! INSTALL = install -c
  134.   
  135.   # Compiler to use for compiling gnulib.
  136.   # OLDCC should not be the GNU C compiler.
  137. --- 28,34 ----
  138.   AR = ar
  139.   SHELL = /bin/sh
  140.   # on sysV, define this as cp.
  141. ! INSTALL = cp
  142.   
  143.   # Compiler to use for compiling gnulib.
  144.   # OLDCC should not be the GNU C compiler.
  145. ***************
  146. *** 145,151 ****
  147.    symout.o dbxout.o sdbout.o emit-rtl.o insn-emit.o \
  148.    integrate.o jump.o cse.o loop.o flow.o stupid.o combine.o \
  149.    regclass.o local-alloc.o global-alloc.o reload.o reload1.o caller-save.o \
  150. !  insn-peep.o final.o recog.o insn-recog.o insn-extract.o insn-output.o
  151.   
  152.   # Files to be copied away after each stage in building.
  153.   STAGE_GCC=gcc
  154. --- 145,151 ----
  155.    symout.o dbxout.o sdbout.o emit-rtl.o insn-emit.o \
  156.    integrate.o jump.o cse.o loop.o flow.o stupid.o combine.o \
  157.    regclass.o local-alloc.o global-alloc.o reload.o reload1.o caller-save.o \
  158. !  insn-peep.o final.o recog.o insn-recog.o insn-extract.o insn-output.o pragma.o
  159.   
  160.   # Files to be copied away after each stage in building.
  161.   STAGE_GCC=gcc
  162. *** ../gcc-1.37.old/config/tm-xenix386.h    Tue Apr 24 00:34:20 1990
  163. --- ./config/tm-xenix386.h    Mon Apr 30 20:41:53 1990
  164. ***************
  165. *** 26,37 ****
  166.   
  167.   /* By default, target has a no 80387.  */
  168.   
  169. ! #define TARGET_DEFAULT 0
  170.   
  171.   /* Use crt1.o as a startup file and crtn.o as a closing file.  */
  172.   
  173. ! #define STARTFILE_SPEC  "Sseg.o%s Scrt0.o%s"
  174.   
  175.   #define LIB_SPEC "Slibcfp.a%s Slibc.a%s"
  176.   
  177.   #define LINK_SPEC "-i"
  178. --- 26,41 ----
  179.   
  180.   /* By default, target has a no 80387.  */
  181.   
  182. ! #define TARGET_DEFAULT 1
  183.   
  184.   /* Use crt1.o as a startup file and crtn.o as a closing file.  */
  185.   
  186. ! #define STARTFILE_SPEC  "Sseg.o%s %{!p:Scrt0.o%s} %{p:Smcrt0.o%s}"
  187.   
  188. + /* -v is appropriate for use with GAS */
  189. + #define ASM_SPEC    "%{v}"
  190.   #define LIB_SPEC "Slibcfp.a%s Slibc.a%s"
  191.   
  192.   #define LINK_SPEC "-i"
  193. ***************
  194. *** 55,63 ****
  195.   
  196.   #undef SDB_DEBUGGING_INFO
  197.   
  198. ! /* We don't want to output DBX debugging information.  */
  199.   
  200. ! #undef DBX_DEBUGGING_INFO
  201.   
  202.   /* Implicit library calls should use memcpy, not bcopy, etc.  */
  203.   
  204. --- 59,67 ----
  205.   
  206.   #undef SDB_DEBUGGING_INFO
  207.   
  208. ! /* We want to output DBX debugging information.  */
  209.   
  210. ! #define DBX_DEBUGGING_INFO
  211.   
  212.   /* Implicit library calls should use memcpy, not bcopy, etc.  */
  213.   
  214. ***************
  215. *** 65,71 ****
  216.   
  217.   /* Writing `int' for a bitfield forces int alignment for the structure.  */
  218.   
  219. ! #define PCC_BITFIELD_TYPE_MATTERS
  220.   
  221.   /* Generate an external symbol request for __fltused if 80387 selected */
  222.   
  223. --- 69,75 ----
  224.   
  225.   /* Writing `int' for a bitfield forces int alignment for the structure.  */
  226.   
  227. ! #undef PCC_BITFIELD_TYPE_MATTERS
  228.   
  229.   /* Generate an external symbol request for __fltused if 80387 selected */
  230.   
  231. ***************
  232. *** 99,101 ****
  233. --- 103,113 ----
  234.   
  235.   #undef ASM_OUTPUT_CASE_END
  236.   #define ASM_OUTPUT_CASE_END(FILE,NUM,INSN) text_section()
  237. + #undef FUNCTION_PROFILER
  238. + #define FUNCTION_PROFILER(FILE, LABELNO)  \
  239. +    fprintf (FILE, "\tmovl $%sP%d,%%edx\n\tcall __mcount\n", LPREFIX, (LABELNO));
  240. + /* Implement Microsoft C compatible #pragma pack() */
  241. + #define PRAGMA_PACK
  242. *** ../gcc-1.37.old/config/tm-xgas386.h    Tue Apr 24 00:34:20 1990
  243. --- ./config/tm-xgas386.h    Tue Apr 24 11:07:57 1990
  244. ***************
  245. *** 18,24 ****
  246. --- 18,28 ----
  247.   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  248.   
  249.   
  250. + #ifdef PRAGMA_PACK
  251. + #define TARGET_VERSION fprintf (stderr, " (80386, Xenix GAS syntax, #pragma pack() support included)");
  252. + #else
  253.   #define TARGET_VERSION fprintf (stderr, " (80386, Xenix GAS syntax)");
  254. + #endif
  255.   
  256.   /* Define the syntax of instructions and addresses.  */
  257.   
  258. *** ../gcc-1.37.old/fix.h.xenix    Thu Jan  1 00:00:00 1970
  259. --- ./fix.h.xenix    Wed Apr 25 17:52:02 1990
  260. ***************
  261. *** 0 ****
  262. --- 1,146 ----
  263. + :
  264. + # @(#)$Header: /pdsrc/Local/RCS/fix.h.xenix,v 1.1 90/04/25 18:51:21 root Exp $
  265. + #
  266. + # (C) Copyright 1990 Ronald Khoo <ronald@robobar.co.uk>
  267. + # Permission granted to use or abuse this program for any purpose,
  268. + # provided that all modified copies are clearly marked as such.
  269. + # No warranty is given for the fitness of this program for any purpose.
  270. + # Please treat this file as a document saying what I did and not a program.
  271. + # Please mail me any changes you make, I will coordinate patches.
  272. + #
  273. + # This is a quick hack to fix the SCO Xenix 386 include files so that
  274. + # they work correctly with gcc.  No attempt has been made to do this
  275. + # in a general way whatsoever, and this script was not made with any
  276. + # reference to the GCC fixincludes script:  I still have no idea what
  277. + # that does.  This works (ish) for me.  Your mileage may vary.
  278. + # My include files were from the 2.3.2 operating system and the 2.3
  279. + # development system.  I'll be interested to hear what works for 2.2 based
  280. + # systems.
  281. + #
  282. + # If your stddef.h says #ifdef M_XENIX #define _SIZE_T, remove those 3 lines.
  283. + # (That was a hack Steve put in that is no longer needed once you run this
  284. + #  program)
  285. + # You should also change the typedef of size_t in there to read:
  286. + # typedef unsigned int size_t;
  287. + #
  288. + # * stream edit files from /usr/include and /usr/include/sys
  289. + #   into /usr/local/lib/gcc-include, skipping those which are
  290. + #   provided by GCC.
  291. + # * make all references to M_I386 refer to __M_I386__ instead.
  292. + #   This enables programs compiled with gcc -ansi not to coredump.
  293. + #   This only works with gcc so don't give these hacked .h files to cc !!
  294. + # * put protection #ifdef tests to all files to allow them to be safely
  295. + #   multiply included.
  296. + # * time_t and size_t seem to be typedefed all over the place.  Protect them.
  297. + #
  298. + # My sys/signal.h seemed to define some things as void and some as int. Barf.
  299. + # I made it all say void by using the probably flakey ed script below
  300. + # that's only run if you give the -all argument.
  301. + # It works for me, but I don't trust it to work with your sys/signal.h
  302. + # without your looking at it first.
  303. + # I don't know how to write a C parser in sed.
  304. + #
  305. + # I also made the buffer arguments in stdio.h to fread and fwrite
  306. + # void* instead of char* because I prefer to limit the warning messages I read
  307. + # to those that matter.  What does ANSI say they should be ?
  308. + # You should remove declaration of va_list from stdio.h.  This is bogus.
  309. + # Both these are also done in another ed script below that's only run if
  310. + # you say -all.
  311. + #
  312. + # $Log:    fix.h.xenix,v $
  313. + # Revision 1.1  90/04/25  18:51:21  root
  314. + # Initial revision
  315. + # 
  316. + PATH=/etc:/bin:/usr/bin export PATH
  317. + # usage: /usr/local/lib/fix.h.xenix [ -all ]
  318. + # saying -all implies that you have stock 2.3 Dev Sys include files and
  319. + # you want them to look like mine.
  320. + script='
  321. + /M_I386/s//__&__/g
  322. + /typedef.*[     ]time_t/ {
  323. + i\
  324. + #ifndef _TIME_T
  325. + i\
  326. + #define _TIME_T
  327. + a\
  328. + #endif /* _TIME_T */
  329. + }
  330. + /typedef.*[     ]size_t/ {
  331. + i\
  332. + #ifndef _SIZE_T
  333. + i\
  334. + #define _SIZE_T
  335. + a\
  336. + #endif /* _SIZE_T */
  337. + }
  338. + '
  339. + [ -d /usr/local/lib/gcc-include ] || mkdir /usr/local/lib/gcc-include
  340. + [ -d /usr/local/lib/gcc-include/sys ] || mkdir /usr/local/lib/gcc-include/sys
  341. + cd /usr/include
  342. + for i in *.h  sys/*.h
  343. + do
  344. + case $i in
  345. + assert.h)    ;;    # Use the GCC supplied versions of these 6 files
  346. + float.h)    ;;
  347. + limits.h)    ;;
  348. + stdarg.h)    ;;
  349. + stddef.h)    ;;
  350. + varargs.h)    ;;
  351. + *)
  352. +     echo Hacking $i >&2
  353. +     name=_INCLUDED_`echo $i | tr './[a-z]' '__[A-Z]'`_AUTOFIX
  354. +     echo "#ifndef $name" > /usr/local/lib/gcc-include/$i
  355. +     echo "#define $name" >> /usr/local/lib/gcc-include/$i
  356. +     sed -e "$script" $i >> /usr/local/lib/gcc-include/$i
  357. +     echo "#endif /* $name */" >> /usr/local/lib/gcc-include/$i
  358. + ;;
  359. + esac
  360. + done
  361. + # This is the bit which tries to edit sys/signal.h
  362. + burp1()
  363. + {
  364. +     echo Hacking sys/signal.h again. Yawn. >&2
  365. +     ed - /usr/local/lib/gcc-include/sys/signal.h <<'EOF'
  366. +     g/^#define.*int[     ]*(\*)/s/int/void/g
  367. +     w
  368. +     q
  369. + EOF
  370. + }
  371. + # This is the bit which tries to edit stdio.h
  372. + burp2()
  373. + {
  374. +     echo Hacking stdio.h again. Yawn. >&2
  375. +     ed - /usr/local/lib/gcc-include/stdio.h <<'EOF'
  376. +     g/typedef.*va_list/d
  377. +     g/^extern.*fread/s/char/void/
  378. +     g/^extern.*fwrite/s/char/void/
  379. +     w
  380. +     q
  381. + EOF
  382. + }
  383. + # Only call with -all if you think your include files look enough like
  384. + # mine for these scripts to work.
  385. + if [ x$1 = x-all ] ; then
  386. +     burp1
  387. +     burp2
  388. + fi
  389. + cd /usr/local/lib/gcc-include
  390. + find . -print | xargs chown bin
  391. + find . -print | xargs chgrp bin
  392. + find . -type f -print | xargs chmod 664
  393. + chmod 775  /usr/local/lib/gcc-include /usr/local/lib/gcc-include/sys
  394. + echo '
  395. + done. Enjoy.
  396. + --Ronald.
  397. + ' >&2
  398. *** ../gcc-1.37.old/gcc.c    Tue Apr 24 00:34:19 1990
  399. --- ./gcc.c    Tue Apr 24 11:07:53 1990
  400. ***************
  401. *** 208,213 ****
  402. --- 208,224 ----
  403.   
  404.   /* This defines which switch letters take arguments.  */
  405.   
  406. + #ifdef M_XENIX
  407. + #ifndef SWITCH_TAKES_ARG
  408. + #define SWITCH_TAKES_ARG(CHAR)      \
  409. +   ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
  410. +    || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
  411. +    || (CHAR) == 'I' || (CHAR) == 'Y' || (CHAR) == 'm' \
  412. +    || (CHAR) == 'L' || (CHAR) == 'i' || (CHAR) == 'A' \
  413. +    || (CHAR) == 'F')
  414. + #endif
  415. + #endif
  416.   #ifndef SWITCH_TAKES_ARG
  417.   #define SWITCH_TAKES_ARG(CHAR)      \
  418.     ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
  419. ***************
  420. *** 417,423 ****
  421.   
  422.   /* Here is the spec for running the linker, after compiling all files.  */
  423.   #ifdef M_XENIX
  424. ! char *link_spec = "%{!c:%{!M*:%{!E:%{!S:ld %{o*} %l %{g:-g}\
  425.    %{!nostdlib:%S} %{!o:-o a.out} %o %Z %{!nostdlib:gnulib%s %L }\n }}}}";
  426.   #else /* not M_XENIX */
  427.   char *link_spec = "%{!c:%{!M*:%{!E:%{!S:ld %{o*} %l\
  428. --- 428,435 ----
  429.   
  430.   /* Here is the spec for running the linker, after compiling all files.  */
  431.   #ifdef M_XENIX
  432. ! char *link_spec = "%{!c:%{!M*:%{!E:%{!S:ld %{o*} %l %{g:-g} \
  433. !  %{A} %{F} %{r} %{s} %{u*} \
  434.    %{!nostdlib:%S} %{!o:-o a.out} %o %Z %{!nostdlib:gnulib%s %L }\n }}}}";
  435.   #else /* not M_XENIX */
  436.   char *link_spec = "%{!c:%{!M*:%{!E:%{!S:ld %{o*} %l\
  437. *** ../gcc-1.37.old/pragma.c    Thu Jan  1 00:00:00 1970
  438. --- ./pragma.c    Tue Apr 24 11:07:57 1990
  439. ***************
  440. *** 0 ****
  441. --- 1,26 ----
  442. + #define DEFAULT_ALIGN    32
  443. + static int pack_align = DEFAULT_ALIGN;
  444. + static int was_pragma = 0;
  445. + pragma_pack(val)
  446. + int val;
  447. + {
  448. +     pack_align = 8 * val;
  449. +     was_pragma = 1;
  450. + }
  451. + pragma_align_val()
  452. + {
  453. +     return pack_align;
  454. + }
  455. + pragma_pack_default()
  456. + {
  457. +     pack_align = DEFAULT_ALIGN;
  458. + }
  459. + int pragma_pack_seen()
  460. + {
  461. +     return was_pragma;
  462. + }
  463. *** ../gcc-1.37.old/stddef.h    Tue Apr 24 00:34:19 1990
  464. --- ./stddef.h    Tue Apr 24 11:07:53 1990
  465. ***************
  466. *** 7,16 ****
  467.   
  468.   /* Unsigned type of `sizeof' something.  */
  469.   
  470. - #ifdef M_XENIX
  471. - #define _SIZE_T
  472. - #endif
  473.   #ifndef _SIZE_T    /* in case <sys/types.h> has defined it. */
  474.   #define _SIZE_T
  475.   typedef unsigned long size_t;
  476. --- 7,12 ----
  477. *** ../gcc-1.37.old/stor-layout.c    Wed Jan 17 18:21:06 1990
  478. --- ./stor-layout.c    Tue Apr 24 11:07:56 1990
  479. ***************
  480. *** 498,503 ****
  481. --- 498,507 ----
  482.        or some divisor of it.  */
  483.   
  484.         layout_decl (field, var_size ? size_unit : const_size);
  485. + #ifdef PRAGMA_PACK
  486. +       if (pragma_pack_seen())
  487. +         DECL_ALIGN(field) = MIN(pragma_align_val(), DECL_ALIGN(field));
  488. + #endif
  489.         desired_align = DECL_ALIGN (field);
  490.   
  491.         /* Record must have at least as much alignment as any field.
  492. *** ../gcc-1.37.old/c-parse.tab.c    Wed Jan 17 06:13:47 1990
  493. --- ./c-parse.tab.c    Tue Apr 24 11:08:01 1990
  494. ***************
  495. *** 2906,2911 ****
  496. --- 2906,2952 ----
  497.             && getc (finput) == 'm'
  498.             && getc (finput) == 'a'
  499.             && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
  500. + #ifdef PRAGMA_PACK
  501. +       {
  502. +         token = yylex();
  503. +             if (token != IDENTIFIER)
  504. +             goto skipline;
  505. +             if (strcmp(token_buffer, "pack") != 0)
  506. +                 goto skipline;
  507. +         token = yylex();
  508. +           if (token != '(') {
  509. +             error ("invalid #pragma pack expecting '('");
  510. +             goto skipline;
  511. +         }
  512. +         /* setup default alignment first */
  513. +         pragma_pack_default();
  514. +         token = yylex();
  515. +         if (token != ')')
  516. +         {
  517. +             if (token == CONSTANT
  518. +                 && TREE_CODE (yylval.ttype) == INTEGER_CST) {
  519. +                 int l = TREE_INT_CST_LOW (yylval.ttype);
  520. +                 pragma_pack(l);
  521. +             }
  522. +             else {
  523. +                 error ("invalid #pragma pack expecting 1, 2 or 4");
  524. +                 goto skipline;
  525. +             }
  526. +             token = yylex();
  527. +         }
  528. +           if (token != ')') {
  529. +             error ("invalid #pragma pack expecting ')'");
  530. +             goto skipline;
  531. +         }
  532. +         }
  533. + #endif
  534.           goto skipline;
  535.       }
  536.   
  537. *** packtest.c.old    Thu Jan  1 00:00:00 1970
  538. --- packtest.c    Mon Apr 30 20:57:14 1990
  539. ***************
  540. *** 0 ****
  541. --- 1,95 ----
  542. + static char *rcsid = "@(#)$Header: /pdsrc/Local/RCS/packtest.c,v 1.1 90/04/26 17:50:35 root Exp $";
  543. + /*
  544. +  * Regression test to check that gcc's #pragma pack() support does the
  545. +  * same thing as Microsoft C's.
  546. +  *
  547. +  * Run with this command from sh, not csh, since SCO's csh is BROKEN.
  548. +  * cc packtest.c && ./a.out > m && gcc packtest.c && ./a.out > g && diff m g
  549. +  * You should not see any output.
  550. +  *
  551. +  * $Log:    packtest.c,v $
  552. +  * Revision 1.1  90/04/26  17:50:35  root
  553. +  * Initial revision
  554. +  * 
  555. +  */
  556. + #pragma pack(4)
  557. + struct s1 {
  558. +     char one;
  559. +     int  two;
  560. +     long three;
  561. +     double four;
  562. + } s1;
  563. + #pragma pack(2)
  564. + struct s2 {
  565. +     char one;
  566. +     int  two;
  567. +     long three;
  568. +     double four;
  569. + } s2;
  570. + #pragma pack(1)
  571. + struct s3 {
  572. +     char one;
  573. +     int  two;
  574. +     long three;
  575. +     double four;
  576. + } s3;
  577. + #pragma pack()
  578. + struct s4 {
  579. +     char one;
  580. +     int  two;
  581. +     long three;
  582. +     double four;
  583. + } s4;
  584. + struct biggie {
  585. +     struct s3 x1;
  586. +     struct s1 b1;
  587. +     struct s3 x2;
  588. +     struct s2 b2;
  589. +     struct s3 x3;
  590. +     struct s3 b3;
  591. +     struct s3 x4;
  592. +     struct s4 b4;
  593. + } b;
  594. + #define offsetof(TYPE, MEMBER) ((unsigned) &((TYPE *)0)->MEMBER)
  595. + main()
  596. + {
  597. +     printf("% 4d% 4d% 4d\n",
  598. +         offsetof(struct s1, two),
  599. +         offsetof(struct s1, three),
  600. +         offsetof(struct s1, four));
  601. +     printf("% 4d% 4d% 4d\n",
  602. +         offsetof(struct s2, two),
  603. +         offsetof(struct s2, three),
  604. +         offsetof(struct s2, four));
  605. +     printf("% 4d% 4d% 4d\n",
  606. +         offsetof(struct s3, two),
  607. +         offsetof(struct s3, three),
  608. +         offsetof(struct s3, four));
  609. +     printf("% 4d% 4d% 4d\n",
  610. +         offsetof(struct s4, two),
  611. +         offsetof(struct s4, three),
  612. +         offsetof(struct s4, four));
  613. +     printf("\n% 4d% 4d% 4d\n",
  614. +         ((char *)&b.b1.two) - ((char *)&b.b1.one),
  615. +         ((char *)&b.b1.three) - ((char *)&b.b1.one),
  616. +         ((char *)&b.b1.four) - ((char *)&b.b1.one));
  617. +     printf("% 4d% 4d% 4d\n",
  618. +         ((char *)&b.b2.two) - ((char *)&b.b2.one),
  619. +         ((char *)&b.b2.three) - ((char *)&b.b2.one),
  620. +         ((char *)&b.b2.four) - ((char *)&b.b2.one));
  621. +     printf("% 4d% 4d% 4d\n",
  622. +         ((char *)&b.b3.two) - ((char *)&b.b3.one),
  623. +         ((char *)&b.b3.three) - ((char *)&b.b3.one),
  624. +         ((char *)&b.b3.four) - ((char *)&b.b3.one));
  625. +     printf("% 4d% 4d% 4d\n\n",
  626. +         ((char *)&b.b4.two) - ((char *)&b.b4.one),
  627. +         ((char *)&b.b4.three) - ((char *)&b.b4.one),
  628. +         ((char *)&b.b4.four) - ((char *)&b.b4.one));
  629. +     printf("    % 4d% 4d\n", sizeof b.b1, (char *)&b.b1 - (char *)&b);
  630. +     printf("    % 4d% 4d\n", sizeof b.b2, (char *)&b.b2 - (char *)&b);
  631. +     printf("    % 4d% 4d\n", sizeof b.b3, (char *)&b.b3 - (char *)&b);
  632. +     printf("    % 4d% 4d\n", sizeof b.b4, (char *)&b.b4 - (char *)&b);
  633. +     exit(0);
  634. + }
  635.  
  636. -- 
  637. Steve.Bleazard@RoboBar.Co.Uk        | Phone:  +44 1 991 1142 x153
  638. Snr Software Engineer, Robobar Ltd. | Fax:    +44 1 998 8343 (G3)
  639. 22 Wadsworth Road, Perivale.        |
  640. Middx., UB6 7JD ENGLAND.            | ...!ukc!robobar!steve
  641.