correct typecast to pass pointers in Hitech C
>>readeeprom(rxbuffer,8,&rxbuffer); <---- this should work,
>if rxbuffer is an
> array of char
it DOES work, and also works for non-array variables, but the compiler
thinks I'm doing something wrong.
>>readeeprom(rxbuffer,8,(char)&rxbuffer); <---- this is wrong, you
>don't want to cast
> the pointer to char!
But a pointer IS a char (i.e. byte) on a pic! I know it, but the
compiler doesn't seem to trust me!
>readeeprom(rxbuffer,8,(char *) &rxbuffer); <---- this is correct, but
>I don't know why you would want to
>write it this way!
I think this is what I was looking for.
There is a VERY good reason why I want to do it this way - maybe I
shouldn't have confused things by using an array as the example!
I want to pass the address of a target variable of ANY type, so my
readeeprom routine can stuff the data straight into the variable,
whether it be a char, int, long or array.
This is much more code, space and time-efficient than passing the
values e.g. :
readeeprom(0,1,(char*)&c); // reads 1 byte to a char
readeeprom(1,2,(char*)&i); // reads 2 bytes to an int
readeeprom(3,4,(char*)&l); // reads 4 bytes to a long
readeeprom(7,6,(char*)&rxbuffer); //reads 6 bytes to rxbuffer[2..7]
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads
In reply to: <firstname.lastname@example.org>
See also: www.piclist.com/techref/microchip/languages.htm?key=c
You must be a member of the
piclist mailing list
(not only a www.piclist.com member) to post to the