home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / sun / misc / 3984 < prev    next >
Encoding:
Text File  |  1992-09-02  |  1.2 KB  |  44 lines

  1. Xref: sparky comp.sys.sun.misc:3984 comp.lang.c:12907
  2. Path: sparky!uunet!mcsun!news.funet.fi!hydra!klaava!wirzeniu
  3. From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
  4. Newsgroups: comp.sys.sun.misc,comp.lang.c
  5. Subject: Re: Strange error in C compiler
  6. Keywords: dynamic linking C compilation constant pointer
  7. Message-ID: <1992Aug28.102627.25185@klaava.Helsinki.FI>
  8. Date: 28 Aug 92 10:26:27 GMT
  9. References: <13271.714953297@kiae.su>
  10. Organization: University of Helsinki
  11. Lines: 31
  12.  
  13. [ quotes have been reformatted for brevity --liw ]
  14.  
  15. leo@ipmce.su asks why this doesn't work:
  16. >extern _DYNAMIC[];
  17. >main() { if (_DYNAMIC) puts("Dynamic"); else puts("Static"); }
  18.  
  19. but replacing the test with ``if (_DYNAMIC != (int*) 0)'' works.
  20.  
  21. One guess: Since you have declared _DYNAMIC as an array, and no data
  22. object can have the address NULL, the compiler may have optimized away
  23. the test, because its value is always known to be true:
  24.  
  25.     if (_DYNAMIC)
  26.         puts("Dynamic");
  27.     else
  28.         puts("Static");
  29.  
  30. becomes after some analysis the same as:
  31.  
  32.     if (1)
  33.         puts("Dynamic");
  34.     else
  35.         puts("Static");
  36.  
  37. I do not know why the second case worked.  Perhaps your optimizer is
  38. less than perfect?
  39.  
  40. Maybe _DYNAMIC should have been a pointer, or an int?
  41.  
  42. --
  43. Lars.Wirzenius@helsinki.fi
  44.