Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!bellcore!faline!thumper!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: Ambiguous C? Message-ID: <9249@alice.UUCP> Date: 27 Apr 89 14:25:30 GMT References: <111@ssp1.idca.tds.philips.nl> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 40 In article <111@ssp1.idca.tds.philips.nl>, roelof@idca.tds.PHILIPS.nl (R. Vuurboom) writes: > The following piece of code got me into trouble. > I needed to access a register which only allows long accesses. . . . > Does C specify which (if any) interpretation is correct? > #define SCUCMD 0 > #define SCU_BDID 0x2000 /* bit 14 */ > if ( (*(int *)(SCUCMD)) & SCU_BDID ) There are two separate questions: 1. Does C define the meaning of this program fragement? 2. How do you get the compiler to do what you want? The answer to (1) is `no' -- once you cast an integer into a pointer, you're on your own. In practice, what's probably happening is that the compiler realizes that there's only one bit turned on in the value of SCU_BDID, so it's optimizing the code by not fetching the entire word to test. To suppress the optimization, you can probably conceal the value of SCU_BDID from the compiler by using it in a way that the compiler thinks might change. For instance: static int SCU_BDID = 0x2000; Now the compiler probably won't be smart enough to realize that SCU_BDID is really a constant, so it will have to generate code that caters to any bit in the whole word being on. -- --Andrew Koenig ark@europa.att.com