View Single Post
  #3   Spotlight this post!  
Unread 28-01-2007, 21:49
htwiz2002's Avatar
htwiz2002 htwiz2002 is offline
Htwizard
AKA: Anthony Takata Bawahawba
#1290
Team Role: Engineer
 
Join Date: Jan 2004
Location: Chandler, AZ
Posts: 23
htwiz2002 will become famous soon enough
Re: Pointers/References?

Quote:
Originally Posted by buddy.smith View Post
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)


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
Well, the idea is that I can simply specify a variable into the function so that the function can load the value into the variable, rather than having to call it and then store the information. its' purpose is to save space and ease of use, not reverse it. The point is to simply call the function to load four variables in the set (part of the autonomous routine). The other half of the function uses the same input to save it.

Is there a way to make the multi-variable-in-the-input idea work? It cleans the code up so much that I would rather keep it that way. Can someone at least tell me why I get that message about a "suspicious pointer conversion"? I'm sure the code would work if I could pass more than just one variable into the function (which is what it seems).
__________________
TsAuKpAeTrA (Anthony)