piclist 2001\07\11\134111a >
Thread: correct typecast to pass pointers in Hitech C
www.piclist.com/techref/microchip/languages.htm?key=c
flavicon
face BY : mikeKILLspam@RemoveMEwhitewing.co.uk



>>readeeprom(rxbuffer[2],8,&rxbuffer[0]);                <---- 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[2],8,(char)&rxbuffer[0]);   <---- 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[2],8,(char *) &rxbuffer[0]); <---- 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. :
char c;
int i;
long l;
char buffer[8];

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[2]); //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


<nnvoktg9m9ch15jq54gvg4h1irr85soqjq@4ax.com> quoted-printable

In reply to: <3.0.3.32.20010711092119.02808980@interlog.com>
See also: www.piclist.com/techref/microchip/languages.htm?key=c
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) correct typecast to pass pointers in Hitech C

month overview.

new search...