This should be an easy one.... I am trying to write a function to modify physical registers by their address (not their name in the IO header file). How can I directly affect an address in C (assuming a Cosmic compiler)? Something like.....
function(char address, char modifier) { //Stub to modify value in address }
function(const unsigned int address, char modifier) { // Note address is now int char * pointer_to_register; pointer_to_register = address; // point pointer at the required register *pointer_to_register = modifier; // modify contents of address } // Another method would be to pass the address as a pointer function(char *address, char modifier) { *address = modifier; // modify contents of address } BM
Hmmm... I got an invalid indirection operand message. Here is what my code looks like:
function() { char temp1, temp2; temp1 = array[offset]; //Array contains address to be modified temp2 = *temp1; } Shouldn't temp2 show the contents of the address stored in temp1? BTW, thanks for the quick response Battman.
Posted on February 23, 2004 at 19:19temp1 & temp2 are both local variables of type char. The line temp2 = *temp1; assumes that temp1 is a char pointer eg its was declared as: char * temp1; Try this: function() { char * temp1 char temp2; temp1 = &array[offset]; //Array contains address to be modified temp2 = *temp1; } If you have access to a copy of 'The C programming language' 2nd edition by K&R there is a really handy code fragment & explaination on page 94 . BM
You would have been 100% correct assuming that my array was initialized as the correct data type. All I had to do to your code was type cast the array. Thanks for your help!