'AS1_SendBlock' makes integer from pointer without a cast --- warning

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

'AS1_SendBlock' makes integer from pointer without a cast --- warning

2,244 Views
russellsher
Contributor III

I am using processor expert to make a uart as below:

int main(void)

{

  char OutData[] = "Hello world";

  LDD_TError Error;

  LDD_TDeviceData *MySerialPtr;

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/

  PE_low_level_init();

  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */

  for(;;)

  {

   Set_Led_SetVal();  // Led on

   AS1_SendChar('A'); // Send a Char

   Error = AS1_SendBlock(MySerialPtr, OutData, sizeof(OutData)); /* Send block of characters */

  }

I get this warning:

passing argument 2 of 'AS1_SendBlock' makes integer from pointer without a cast [enabled by default]

passing argument 3 of 'AS1_SendBlock' makes pointer from integer without a cast [enabled by default]

I'm not quite sure what I should change, any advice?

thanks

Russell

Labels (1)
11 Replies

1,570 Views
Jonathan_Iglesias
NXP TechSupport
NXP TechSupport

Hi, Rusell.

Can you send me the project so I can check it , to see whats going wrong, by the way, those are warnings  and should let your code debug.

but  send me the project I'll check it  to see whats wrong.

Regards.

-Jonathan

0 Kudos

1,570 Views
russellsher
Contributor III

Hi and Thanks

I have attached the project as a zipped file.

(Freedom_1   -- after freedom board

thanks

Russell

0 Kudos

1,570 Views
russellsher
Contributor III

I had commented out that line, so just take out the comment in front of the line:

// Error = AS1_SendBlock(MySerialPtr, OutData, sizeof(OutData)); /* Send block of characters */

to show the warning.

thanks

Russell

0 Kudos

1,570 Views
Jonathan_Iglesias
NXP TechSupport
NXP TechSupport

Hi, Rusell.

Now I see whats the problem,  the function receive this parameters:

AS1_SendBlock(AS1_TComData *, word , word *)

Word it's declared as Unsigned Short,

What you are sending it's AS1_SendBlock(LDD_TDeviceData, char *, int);

the problem here it's the types because for instance in the second argument, you are sending a string

CodeWarrior automatically  cast it for you thats why the problem its a warning and say [ENABLED BY DEFAULT]

what you can do it's the casting befor you send the  parameters for example in the sizeof  this function return and int what you can do it's this:

word test=sizeof(OutData);

then just send in the function the &test. and the same for the string.

please let me know if it helps.

Regards

-Jonathan

0 Kudos

1,570 Views
russellsher
Contributor III

Hi Johnathan - thanks for replying:

Ok, for the sizeof, I did the cast like you said, so I think that one is ok:

I have:

  word test=sizeof(OutData);

Error = AS1_SendBlock(MySerialPtr, OutData, &test); /* Send block of characters */

Is that correct? Now I'm not quite sure how to cast the Outdata parameter

Could you give an example for that bitplease.

thank-you

Russell

0 Kudos

1,570 Views
russellsher
Contributor III

Edit: Is this correct?

  word test=sizeof(OutData);

  Error = AS1_SendBlock(MySerialPtr, test, &test); /* Send block of characters */

0 Kudos

1,570 Views
BlackNight
NXP Employee
NXP Employee

No, that's not correct.

sizeof() returns the size of the type/object in memory. In your case, OutData is an array with a string, and sizeof() will return the size of the string (in your case!!) including the zero byte at the end.

so sizeof("hello") will be 6, while strlen("hello") will be 5 (without the zero byte at the end).

You need to pass the length (number of characters), so either use sizeof(OutData)-1  or strlen(OutData).

Keep in mind that in your case sizeof() is applied to an array (and *not* to a pointer). Using sizeof() on an array returns the size of the array. Using sizeof() on a pointer returns the size of the pointer (usually 4 bytes on a 32bit architecture).

Erich

1,570 Views
russellsher
Contributor III

Many thanks for the helpful replies

I do get a warning

pointer targets in passing argument 1 of 'strlen' differ in signedness [-Wpointer-sign]main.c

if I do:

Error = AS1_SendBlock(OutData, strlen(OutData), &snt);

I can avoid the warning if I do:

Error = AS1_SendBlock(OutData, strlen((const char*)OutData), &snt);

Does this look like a 'proper' fix?

Russell

0 Kudos

1,570 Views
BlackNight
NXP Employee
NXP Employee

Hi Russel,

I think you are using the AsynchroSerial component (not the LDD?) (I have not checked your project)?

The interface is the following:

byte AS1_SendBlock(AS1_TComData *Ptr, word Size, word *Snd);

(see the implementation/header file).

So to you need to use it that way:

byte res;

byte OutData[] = "Hello";

word snt;

res = AS1_SendBlock(OutData, strlen(OutData), &snt);

Otherwise, there is online help for the components, see Getting Help on Processor Expert Components | MCU on Eclipse

Erich

1,570 Views
russellsher
Contributor III

Hi Erich  Thanks for reply, yes I am using the AsynchroSerial component

I'll check out the online help.


Although I was using the example from: Serial_LDD Embedded Component User Guide which gave:

0 Kudos

1,570 Views
russellsher
Contributor III

What is the I had a look at the help on components:

I see there is a Sendblock under Asynchroserial and a Sendblock under SerialLdd1:Serial_Ldd

I'm not sure of the difference - Asynchroserial  says 'sends a block to the channel'

SerialLdd1:Serial_Ldd says 'sends a block of charaters'