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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: Is this a Legal Way to Access a Specific Address?
  5. Message-ID: <1993Jan23.194116.16063@taumet.com>
  6. Keywords: DSP, C, ANSI, Fixed RAM
  7. Organization: TauMetric Corporation
  8. References: <1993Jan23.042626.991@verdix.com> <C1AzpG.4xy@cmie.ernet.in>
  9. Date: Sat, 23 Jan 1993 19:41:16 GMT
  10. Lines: 29
  11.  
  12. rs@cmie.ernet.in (Rajappa Iyer) writes:
  13.  
  14. >scotty@verdix.com (Scott R. Chilcote) writes:
  15.  
  16. >>We're programming a device that has a RAM cache at address 809800H.
  17. >>Is it legal to address this memory in C as follows?
  18. >>#define ON_CHIP 0x809800
  19. >>int main(void)
  20. >>{
  21. >>   float *oc_ptr = (float *) ON_CHIP;
  22.  
  23. >It is definitely legal C.
  24.  
  25. It is syntactically legal C, but the results of using the code are
  26. undefined by any standard.  That is to say, you can't predict
  27. a priori whether the code will do what you want.
  28.  
  29. Compilers typically have ways of allowing absolute machine addresses to
  30. be assigned to pointers, but the method depends on the machine and the
  31. compiler.  You have to check the compiler manual.
  32.  
  33. If parts of the code are machine-specific, as this clearly is, it is
  34. usually a good idea to isolate such code in separate modules.  That
  35. code is then tailored for the machine and compiler.  The remainder
  36. of the code (assumed to be portable) can be left alone when you change
  37. compilers or machines.
  38. -- 
  39.  
  40. Steve Clamage, TauMetric Corp, steve@taumet.com
  41.