home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / sun / misc / 3976 < prev    next >
Encoding:
Text File  |  1992-08-27  |  972 b   |  48 lines

  1. Xref: sparky comp.sys.sun.misc:3976 comp.lang.c:12896
  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: Strange error in C compiler
  6. Message-ID: <13271.714953297@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. Date: Thu, 27 Aug 1992 21:42:27 +0400
  13.  
  14.     Hello all!
  15.  
  16. Consider the following code:
  17.  
  18. /*
  19.     _DYNAMIC is linker-defined and may be either 0 or non-zero,
  20.     depending on link mode.
  21. */
  22.  
  23. extern _DYNAMIC[];
  24.  
  25. main() {
  26.     if (_DYNAMIC)
  27.         puts("Dynamic");
  28.     else
  29.         puts("Static");
  30. }
  31.  
  32.     The above code doesn't work, but with if-statement rewritten
  33.     as follows does:
  34.  
  35.     if (_DYNAMIC != (int*) 0)
  36.  
  37.     Could anyone explain why?
  38.  
  39.     Note: in the first case compiler treats else-clause as dead
  40.     code, but in the second one everything is compiled as
  41.     expected.
  42.  
  43.     Regards,
  44. -- 
  45.     Leonid A. Broukhis
  46.  
  47.  
  48.