Interview Questions

How can I access an interrupt vector located at the machines location 0?

C Interview Questions and Answers


(Continued from previous question...)

How can I access an interrupt vector located at the machines location 0?

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.
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.

(Continued on next question...)

Other Interview Questions