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