View Single Post
  #2   Spotlight this post!  
Unread 28-01-2007, 13:38
buddy.smith buddy.smith is offline
Master Control
FRC #1795
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2007
Location: atlanta
Posts: 20
buddy.smith is an unknown quantity at this point
Re: Pointers/References?

Quote:
Originally Posted by htwiz2002 View Post
Code:
void Terminal_eepromreadset(unsigned char set, unsigned char *data1, unsigned char *data2, unsigned char *data3, unsigned char *data4)
{
Why not do this:
Code:
void Terminal_eepromreadset(unsigned char set, unsigned char data[4])
{
    //Consolidate this on verify that it works!!!
    unsigned int address = set * 4;
    data[0] = EEPROM_Read(address);
    data[1] = EEPROM_Read(address + 1);
    data[2] = EEPROM_Read(address + 2);
    data[3] = EEPROM_Read(address + 3);
}
Note that this is the same as:
Code:
void Terminal_eepromreadset(unsigned char set, unsigned char *data)
Quote:
Originally Posted by htwiz2002 View Post
Code:
// later on in another function this is how it's called:
unsigned char version1;
unsigned char version2;
unsigned char version3
unsigned char version4;
Terminal_eepromreadset(0, version1, version2, version3, version4); break;
version1 is a 'char'. Terminal_eepromreadset wants a char*. To convert a char to a char *, you use the addressof operator (&):
Code:
Terminal_eepromreadset(0, &version1,.....)
Alternately, you can use my suggestion:
Code:
unsigned char version[4];
Terminal_eepromreadset(0, version);
In C, an array and a pointer are mostly equivalent. version is a char*, version[N] is a char.

Confusing as dirt?

ttyl,

--buddy