home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.sys.sun.misc:3984 comp.lang.c:12907
- Path: sparky!uunet!mcsun!news.funet.fi!hydra!klaava!wirzeniu
- From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
- Newsgroups: comp.sys.sun.misc,comp.lang.c
- Subject: Re: Strange error in C compiler
- Keywords: dynamic linking C compilation constant pointer
- Message-ID: <1992Aug28.102627.25185@klaava.Helsinki.FI>
- Date: 28 Aug 92 10:26:27 GMT
- References: <13271.714953297@kiae.su>
- Organization: University of Helsinki
- Lines: 31
-
- [ quotes have been reformatted for brevity --liw ]
-
- leo@ipmce.su asks why this doesn't work:
- >extern _DYNAMIC[];
- >main() { if (_DYNAMIC) puts("Dynamic"); else puts("Static"); }
-
- but replacing the test with ``if (_DYNAMIC != (int*) 0)'' works.
-
- One guess: Since you have declared _DYNAMIC as an array, and no data
- object can have the address NULL, the compiler may have optimized away
- the test, because its value is always known to be true:
-
- if (_DYNAMIC)
- puts("Dynamic");
- else
- puts("Static");
-
- becomes after some analysis the same as:
-
- if (1)
- puts("Dynamic");
- else
- puts("Static");
-
- I do not know why the second case worked. Perhaps your optimizer is
- less than perfect?
-
- Maybe _DYNAMIC should have been a pointer, or an int?
-
- --
- Lars.Wirzenius@helsinki.fi
-