home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / gnu / gcc / help / 2520 < prev    next >
Encoding:
Text File  |  1992-11-14  |  3.1 KB  |  99 lines

  1. Newsgroups: gnu.gcc.help
  2. Path: sparky!uunet!convex!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!shasta.nextwave.COM!markg
  3. From: markg@shasta.nextwave.COM (Mark Glasser)
  4. Subject: doubles in structs
  5. Message-ID: <9211132312.AA05716@shasta.nextwave.com>
  6. Sender: daemon@cis.ohio-state.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Fri, 13 Nov 1992 23:12:00 GMT
  10. Lines: 87
  11.  
  12.  
  13. Help!!
  14.  
  15. I'm running on a sun sparc (IPC) with SunOS 4.1.1.  I've configured gcc-2.2.2 as
  16.  
  17.     ./configure --target=sparc-sun-sunos4.1
  18.  
  19. The compiler was built successfully - including the self recompile/compare
  20. steps.  The trouble seems to have to do with doubles in structs.  I have a
  21. struct that looks something like this:
  22.  
  23.     typedef struct
  24.     {
  25.         enum ExprTokenType type;
  26.         union
  27.         {
  28.             unsigned ui;
  29.             int i;
  30.             char *str;
  31.             double f;
  32.             enum Operator oper;
  33.             PTR p;
  34.         } u;
  35.     } ExprToken;
  36.  
  37. When I assign to u.f The program crashes.  Why?
  38.  
  39.     token->u.f = (double)cnv_atof(str);
  40.  
  41. cnv_atof() is a function that converts a string to a double.  This program
  42. works fine using the standard sun C compiler.  Not the new unbundled
  43. compiler, but the old one as shipped with 4.1.1.
  44.  
  45. As an experiment I replaced double f with float f in the union.  This seemed
  46. to work but the program crashed elsewhere where I was assigning to a double
  47. in a struct.  Here's the context of the second failure:
  48.  
  49.     void TaskInsert(module_name, when, id, name, args)
  50.         char *module_name;
  51.         double when;
  52.         TaskId id;
  53.         char *name;
  54.         FLL *args;
  55.     {
  56.         TaskInvocation *ti;
  57.     
  58.         ti = (TaskInvocation*)allocate(Lsizeof(TaskInvocation));
  59.         task->module_name(ti) = module_name;
  60.         task->time(ti)   = when;
  61.         task->id(ti)     = id;
  62.         task->task(ti)   = name;
  63.         task->args(ti)   = args;
  64.             .
  65.             .
  66.             .
  67.  
  68. Here is the TaskInvocation struct
  69.  
  70.     typedef struct
  71.     {
  72.         double time;
  73.         char *module_name;
  74.         TaskId id;
  75.         char *task;
  76.         FLL *args;
  77.     } TaskInvocation;
  78.  
  79.  
  80. I have two suspects.  Doubles are not aligned properly within dynamically
  81. allocated structures.  Or, doubles are not passed in and out of functions
  82. correctly.  Does anyone have any ideas?  Are there any known bugs relating
  83. to this area? Do I have the thing configured correctly?  These code
  84. fragments are from a rather large program.  If these problems do not ring a
  85. bell then I can work on producing a small test case - just let me know.
  86.  
  87. Thanks in advance for any light you can shed on this problem.
  88.  
  89.  
  90. Mark Glasser
  91. ------------------------------------------------------------------------
  92. markg@nextwave.com                            Nextwave Design Automation
  93.                                                 450 San Antonio Road #27
  94.                                                      Palo Alto, CA 94306
  95.                                                     (voice) 415.855.9795
  96.                                                       (fax) 415.855.9792
  97. ------------------------------------------------------------------------
  98.  
  99.