HI, Sorry i misunderstood it. It worked now. Thanks for your help.
Regards, Bai On Mon, Mar 9, 2009 at 12:28 PM, BAI LI <libai0...@gmail.com> wrote: > Hi, > > Yes, I know. > > But in the command defination, I put uint8_t message_array[4], not uint8_t > *message_array as the passing parameter. therefore I am supposed to call the > command with the same type of parameter, but if i use x[4], it pops up that > warning. if I only use x, there is no warning. What is wrong? I didn't use > the array pointer in either command defination or command calling. Then why > warning? > > Cheers, > Bai > > On Mon, Mar 9, 2009 at 12:19 PM, Allan McInnes < > allan.mcin...@canterbury.ac.nz> wrote: > >> The argument declaration >> ..., uint8_t message_array[4], ... >> >> is equivalent to >> >> ..., uint8_t* message_array, ... >> >> So comments that Roy and I previously made still apply. You can get more >> info from the C FAQ: http://c-faq.com/aryptr/aryptrparam.html >> Cheers, >> Allan >> >> >> On 9/03/2009, at 2:12 PM, BAI LI wrote: >> >> Hi, >> >> sorry I was trying to make the code easy understanding. The code is like >> the following. I am trying to manipulating some hash code. >> I didn't use the point structure for array x[]; >> >> ========sha1.h file========= >> typedef struct SHA1Context >> { >> uint32_t Message_Digest[5]; /* Message Digest (output) */ >> uint32_t Length_Low; /* Message length in bits */ >> uint32_t Length_High; /* Message length in bits */ >> unsigned char Message_Block[64]; /* 512-bit message blocks */ >> int Message_Block_Index; /* Index into message block array */ >> int Computed; /* Is the digest computed? */ >> int Corrupted; /* Is the message digest corruped? */ >> } SHA1Context; >> >> ===========testSha1C.nc main program=============== >> #include "sha1.h" >> >> implementation >> { >> SHA1Context sha; >> int i; >> uint8_t x[4]={0x11,0x22,0x33,0x44}; >> >> event void Boot.booted() { >> //power up the cc2420 chip >> call Sha1Control.start(); >> call Timer.startOneShot(10000); >> } >> event void Timer.fired() >> { >> >> call Sha1.resetSHA1(&sha); >> call Sha1.setSHA1Input(&sha, x, 4); >> } >> >> ========command defination============= >> command void Sha1.setSHA1Input(SHA1Context *context,uint8_t >> message_array[4],unsigned length) >> { >> uint32_t time; >> int i=0; >> if (!length) >> { >> return; >> // return; >> } >> printf("setSHA1Input"); >> if (context->Computed || context->Corrupted) >> { >> context->Corrupted = 1; >> return; >> } >> while(length-- && !context->Corrupted && i<4) >> { >> context->Message_Block[context->Message_Block_Index++] = >> (message_array[i] & 0xFF); >> context->Length_Low += 8; >> /* Force it to 32 bits */ >> context->Length_Low &= 0xFFFFFFFF; >> if (context->Length_Low == 0) >> { >> context->Length_High++; >> /* Force it to 32 bits */ >> context->Length_High &= 0xFFFFFFFF; >> if (context->Length_High == 0) >> { >> /* Message is too long */ >> context->Corrupted = 1; >> } >> } >> if (context->Message_Block_Index == 64) >> { >> call Sha1.setSHA1ProcessMessageBlock(context); >> } >> i++; >> } >> >> Then I got the warning: >> TestSha1C.nc:95: warning: passing argument 2 of `Sha1.setSHA1Input' makes >> pointe >> r from integer without a cast >> On Mon, Mar 9, 2009 at 11:57 AM, Roy Shea <roys...@gmail.com> wrote: >> >>> Howdy, >>> >>> > uint8_t array[4]={0x11,0x22,0x33,0x44}; >>> > ... >>> > call abc(x[4]); >>> > >>> > I got the warning: >>> > >>> > warning: passing argument 2 of `abc' makes pointer from integer without >>> a cast >>> >>> Not sure why it is referring to argument 2. Was the above warning >>> produced by the sample code you posted? The code you listed also looks >>> ambiguous to me. Let me make a few assumptions: >>> >>> - The function abc is a function expecting an array of unsigned 8 bit >>> integers, so it is a declaration looking like: >>> >>> void abc(uint8_t* data); >>> >>> - The function command has the same prototype as abc >>> >>> - The variable x is the same as the variable array >>> >>> I think this is just a problem with how you are using arrays in C. The >>> type of x is a pointer to unsigned 8 bit integers or, as specified in C, >>> a "uint8_t *". Using: >>> >>> x[4] >>> >>> in C causes the fifth element (yes, this an out of bounds accesses!) of >>> the array to be dereferenced. This element will have type "uint8_t", so >>> the function abc is being given an object of type "uint8_t", or an 8-bit >>> integer. Since the function abc expects something of type "uint8_t *", >>> the compiler warns that it had to convert the integer type into a >>> pointer type. >>> >>> > call command(x); >>> >>> In this case the function called "command" is being given an object of >>> type "uint8_t *". Since this is what the function expects, no warning >>> is generated. >>> >>> If you're rusty on C pointers and arrays, you may want to brush up on >>> them. A search for "c array tutorial" will bring up lots of hits. >>> >>> Peace, >>> -Roy >>> >> >> >> >
_______________________________________________ Tinyos-help mailing list Tinyos-help@millennium.berkeley.edu https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help