home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20109 < prev    next >
Encoding:
Text File  |  1993-01-23  |  1.7 KB  |  45 lines

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