home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / dsp / 3073 < prev    next >
Encoding:
Text File  |  1993-01-24  |  2.4 KB  |  60 lines

  1. Xref: sparky comp.dsp:3073 comp.lang.c:20119
  2. Newsgroups: comp.dsp,comp.lang.c
  3. Path: sparky!uunet!emba-news.uvm.edu!sadye.emba.uvm.edu!wollman
  4. From: wollman@sadye.emba.uvm.edu (Garrett Wollman)
  5. Subject: Re: Is this a Legal Way to Access a Specific Address?
  6. Message-ID: <1993Jan23.181029.29389@uvm.edu>
  7. Keywords: DSP, C, ANSI, Fixed RAM
  8. Sender: news@uvm.edu
  9. Organization: University of Vermont, EMBA Computer Facility
  10. References: <1993Jan23.042626.991@verdix.com>
  11. Date: Sat, 23 Jan 1993 18:10:29 GMT
  12. Lines: 46
  13.  
  14. In article <1993Jan23.042626.991@verdix.com> scotty@verdix.com (Scott R. Chilcote) writes:
  15. >
  16. >Is it legal to address this memory in C as follows?
  17. >
  18. >#define ON_CHIP 0x809800
  19.  
  20. >   float *oc_ptr = (float *) ON_CHIP;
  21.  
  22. >Our device-specific ANSI C compiler lets us do this in order to address the
  23. >on-chip memory, without a warning.  The emulator shows that it works.  I've
  24. >looked in several textbooks, however, and I've never seen mention of setting
  25. >a pointer equal to a constant in order to define a specific address.  Even the
  26. >new K & R book doesn't mention if this is legal.
  27.  
  28. It is certainly "legal" in the sense that it is syntactically correct,
  29. but the results of doing this are implementation-defined.  (Your
  30. compiler manual should somewhere have a paragraph explaining what
  31. precisely it defines this expression to mean.)  The ANSI C standard
  32. *does* guarantee (I believe, not having a copy handy) that there is
  33. some flavor of integer that can be cast back and forth to a pointer
  34. type.  (Different kinds of pointers may require different kinds of
  35. integers.)  I do not believe that you are guaranteed to get the same
  36. integer back; i.e., (unsigned long)(void *)0xfe100004 is not
  37. guaranteed to be == to 4262461444UL.
  38.  
  39. Some people prefer to use a union for type punning; i.e.:
  40.  
  41. union Pointer {
  42.   void *vp;
  43.   unsigned long ul;
  44.   void (*vfp)();
  45. };
  46.  
  47. However, I don't believe that this really buys you anything, although
  48. it may eliminate warning messages on some compilers.  (As someone said
  49. in this newsgroup, "A compiler is free to issue a diagnostic if it's
  50. after five on Friday, or it's raining outside.")  The experts will
  51. probably weigh in soon enough.
  52.  
  53. -GAWollman
  54.  
  55. -- 
  56. Garrett A. Wollman   | Shashish is simple, it's discreet, it's brief. ... 
  57. wollman@emba.uvm.edu | Shashish is the bonding of hearts in spite of distance.
  58. uvm-gen!wollman      | It is a bond more powerful than absence.  We like people
  59. UVM disagrees.       | who like Shashish.  - Claude McKenzie + Florent Vollant
  60.