On Apr 7, 12:40 pm, Ian Collins <ian-n...@hotmail.com> wrote:
> On 04/ 8/11 07:10 AM, cerr wrote:
>
>
>
>
>
>
>
>
>
> > Hi There,
>
> > I came up with following sample code to demonstrate my issue:
> > #include<18F87K22.h>
> > #device HIGH_INTS=TRUE, adc=16, ICD=TRUE
> > #fuses NOWDT //No Watch Dog Timer
> > #fuses WDT128 //Watch Dog Timer uses 1:128
> > #fuses HSM //Hi-Speed crystal oscillator
> > #fuses NOBROWNOUT //No brownout reset
> > #fuses NOPLLEN //No PLL enabled
> > #fuses BBSIZ1K //1K words Boot Block size
> > #fuses NOXINST //Extended set extension and
> > Indexed
>
> > typedef struct{
> > int8 foo,
> > test;
> > } TheStruct;
>
> > TheStruct mystruct[5];
> > int16 myarr[2];
>
> > void Func(TheStruct *data, int16 *arr);
>
> > void main (void)
> > {
> > myarr[0]=0xff;
> > myarr[1]=0xaa;
> > memset(&mystruct,0,sizeof(mystruct));
> > Func(myarr,&mystruct);
> > while(true);
>
> > }
> > //------------------------------------------------------------------------- -----
>
> > void Func(TheStruct *strdat, int16 *arr)
> > {
> > strdat[0]->foo=(*arr[0]);
> > strdat[0]->test=(*arr[1]);
> > }
>
> > This compiles just fine (CCS 4.119) but doesn't work, after the
> > function, foo and test are still 0 cause myarr doesn't seem to be
> > passed correctly to the function.... what am I doing wrong here? :(
>
> Using a poor compiler? With the appropriate headers and typedefs added:
>
> "/tmp/x.c", line 24: warning: argument #1 is incompatible with prototype:
> prototype: pointer to struct {char foo, char test} :
> "/tmp/x.c", line 17
> argument : pointer to short
> "/tmp/x.c", line 24: warning: argument #2 is incompatible with prototype:
> prototype: pointer to short : "/tmp/x.c", line 17
> argument : pointer to array[5] of struct {char foo, char test}
> "/tmp/x.c", line 32: left operand of "->" must be pointer to struct/union
> "/tmp/x.c", line 32: cannot dereference non-pointer type
> "/tmp/x.c", line 33: left operand of "->" must be pointer to struct/union
> "/tmp/x.c", line 33: cannot dereference non-pointer type
>
I got it now,
But why does it work like this:
void Func(TheStruct *strdat, int16 *arr)
{
strdat[0].foo=arr[0];
strdat[0].test=arr[1];
}
strdat is an address passed to the struct & arr is an address to the
array,
why am I not required to dereference these to get the value?
Ron