prev up next   top/contents search

comp.lang.c FAQ list · Question 5.19

Q: How can I access an interrupt vector located at the machine's location 0? If I set a pointer to 0, the compiler might translate it to some nonzero internal null pointer value.


A: Since whatever is at location 0 is obviously machine dependent, you're free to use whatever machine-dependent trick will work to get there. Read your vendor's documentation (and see section 19). It's likely that if it's at all meaningful for you to be accessing location 0, the system will be set up to make it reasonably easy to do so. Some possibilities are:

  1. Simply set a pointer to 0. (This is the way that doesn't have to work, but if it's meaningful, it probably will.)
  2. Assign the integer 0 to an int variable, and convert that int to a pointer. (This is also not guaranteed to work, but it probably will.)
  3. Use a union to set the bits of a pointer variable to 0:
    	union {
    		int *u_p;
    		int u_i;	/* assumes sizeof(int) >= sizeof(int *) */
    	} p;
    
    	p.u_i = 0;
    
  4. Use memset to set the bits of a pointer variable to 0:
    	memset((void *)&p, 0, sizeof(p));
    
  5. Declare an external variable or array
    	extern int location0;
    
    and use an assembly language file, or some special linker invocation, to arrange that this symbol refers to (i.e. the variable is placed at) address 0.

See also questions 4.14 and 19.25.

References: K&R1 Sec. A14.4 p. 210
K&R2 Sec. A6.6 p. 199
ISO Sec. 6.3.4
Rationale Sec. 3.3.4
H&S Sec. 6.2.7 pp. 171-2


prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North