home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!sangam!cmie!rs
- From: rs@cmie.ernet.in (Rajappa Iyer)
- Subject: Re: Is this a Legal Way to Access a Specific Address?
- Message-ID: <C1AzpG.4xy@cmie.ernet.in>
- Keywords: DSP, C, ANSI, Fixed RAM
- Organization: Centre for Monitoring Indian Economy, Bombay
- References: <1993Jan23.042626.991@verdix.com>
- Date: Sat, 23 Jan 1993 10:56:03 GMT
- Lines: 33
-
- scotty@verdix.com (Scott R. Chilcote) writes:
-
-
- >We're programming a device that has a RAM cache at address 809800H.
- >Is it legal to address this memory in C as follows?
- >#define ON_CHIP 0x809800
- >int main(void)
- >{
- > float *oc_ptr = (float *) ON_CHIP;
-
- >Does anyone know if this is acceptable coding, and what kinds of
- >problems could crop up from using this method?
-
- It is definitely legal C. Whether or not it is good programming
- practice is debatable. I personally find it acceptable since the only
- argument against using such techniques is portability --- which does
- not really seem to be an issue here. I presume you are writing a
- device driver.
-
- >The other way we can achieve the same result is using the linker for this
- >device to declare a section of memory at a specific address, and associate
- >a label with the section. We can then use that label with an external pointer
- >declaration in the C program ( extern void *on_chip; ) to reference the
- >specific address we need. This method requires more CPU cycles than the one
- >above to resolve pointers, but at least the address space we're using is
- >declared in the linker's memory map.
-
- Do you really think this would make the program easier to maintain? I
- don't think so.
-
- --
- Rajappa Iyer rs@cmie.ernet.in (Preferred)
- riyer@shakti.ncst.ernet.in
-