home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / sun / misc / 4013 < prev    next >
Encoding:
Text File  |  1992-08-31  |  1.4 KB  |  49 lines

  1. Xref: sparky comp.sys.sun.misc:4013 comp.lang.c:13044
  2. Newsgroups: comp.sys.sun.misc,comp.lang.c
  3. Path: sparky!uunet!mcsun!fuug!kiae!relcom!news-server
  4. From:  Leonid A. Broukhis <leo@ipmce.su>
  5. Subject: SUMMARY: Strange error in C compiler
  6. Message-ID: <6337.715296315@kiae.su>
  7. Keywords: dynamic linking C compilation constant pointer
  8. Lines: 34
  9. Sender: news-server@kiae.su
  10. Reply-To: leo@ipmce.su
  11. Organization: unknown
  12. References: <13271.714953297@kiae.su> <25820@dog.ee.lbl.gov>
  13. Date: Mon, 31 Aug 1992 20:41:13 +0400
  14.  
  15.     The results of the discussion can be summarized as follows:
  16.  
  17.     1) There is the only (almost?) portable way to test the
  18.     value of address constants - to use additional variable:
  19.  
  20.     extern _DYNAMIC[];
  21.  
  22.     /* global - to avoid optimizations, though gcc I use doesn't
  23.      * optimize "if" when pDYNAMIC is local
  24.      */
  25.  
  26.     int * pDYNAMIC = _DYNAMIC;
  27.     ...
  28.     {
  29.         if (pDYNAMIC) ....
  30.         else    ....
  31.     }
  32.  
  33.     I must note the error in some answers. Their authors
  34.     propose to test *_DYNAMIC. Obviously, this may cause NULL
  35.     pointer access and therefore coredump.
  36.  
  37.     2) The source of strange behavior of the C compiler is
  38.     its origin. GCC tries to optimize the "if" always,
  39.     MS-DOS' Microsoft and Borland C don't make any presumptions about
  40.     the value of address constants, and only PCC-derived
  41.     compilers (3 of them have been tested, including SunOS')
  42.     behave strangely.
  43.  
  44.     Thanks,
  45. -- 
  46.     Leonid A. Broukhis
  47.  
  48.  
  49.