From: Bernhard H. <ber...@be...> - 2002-04-26 11:17:52
|
Accessing the upper byte of an address parameter.>I have a function that needs to access the upper byte of an address. I am working on writing an interface to a i2c serial >eeprom, and I would like to pass in an address to make the function more user friendly. Anyway here is the code I have and >the errors I get: >unsigned char eeprom_read(char *readAddr) { > unsigned char retVal; > unsigned char firstByte; > unsigned char secondByte; > // Calculate first and second bytes. > firstByte = (unsigned char)((0xA0) | ((readAddr >> 7) & 0x0E)); > secondByte = (unsigned char)readAddr; My 2 cents: unsigned char firstByte; unsigned char secondByte; void foo (char *readAddr) { firstByte = ((char near *) &readAddr)[0]; secondByte = ((char near *) &readAddr)[1]; } Bernhard |