home *** CD-ROM | disk | FTP | other *** search
- From: Monroe.Thomas@ttlg.UUCP (Monroe Thomas)
- Sender: postmaster@ttlg.UUCP
- Path: sparky!uunet!sun-barr!decwrl!access.usask.ca!kakwa.ucs.ualberta.ca!alberta!ttlg!postmaster
- Newsgroups: comp.lang.c
- Subject: Strange error in C compi
- Message-ID: <714996010.0@ttlg.ttlg.UUCP>
- Date: 28 Aug 92 02:12:00 mst
- Lines: 46
-
- > Hello all!
-
- >Consider the following code:
-
- >/*
- > _DYNAMIC is linker-defined and may be either 0 or non-zero,
- > depending on link mode.
- >*/
-
- >extern _DYNAMIC[];
-
- >main() {
- > if (_DYNAMIC)
- > puts("Dynamic");
- > else
- > puts("Static");
- >}
-
- > The above code doesn't work, but with if-statement rewritten
- > as follows does:
-
- > if (_DYNAMIC != (int*) 0)
-
- > Could anyone explain why?
-
- > Note: in the first case compiler treats else-clause as dead
- > code, but in the second one everything is compiled as
- > expected.
-
- Obviously your compiler as treating _DYNAMIC as never being a null
- pointer. Your first construct is testing the address of the variable,
- your second example is testing the value at that address.
-
- Try dereferencing _DYNAMIC to get a construct similar to your first:
-
- main() {
- if (*_DYNAMIC)
- // note use of *
- puts("Dynamic");
- else
- puts("Static");
- }
-
- * OLX 2.2 * "The little demon was deceitful," Tom implied.
-
- * Origin: Through the Looking Glass (42:100/14)
-