Type Caste Doubt

R

ranjeet.gupta

Dear All

Please check the below code:


UINT8 MsgLength = 0;


MsgLength = strlen((char *)msg);


if ( MsgLength == 0 || MsgLength > 64) {


//Flow A
} else {


//Flow B



}


do you find any issue with the typecasting of the message, will it
create any serious
problem ? As if now I can say that when the message length is more then
256 then it will
fail, apart form this, do any compiler may fail ? looking forward for
the disscussion on this.

Thanks In Advance
Ranjeet Gupta
 
M

mlimber

Dear All

Please check the below code:


UINT8 MsgLength = 0;


MsgLength = strlen((char *)msg);


if ( MsgLength == 0 || MsgLength > 64) {


//Flow A
} else {


//Flow B



}


do you find any issue with the typecasting of the message, will it
create any serious
problem ? As if now I can say that when the message length is more then
256 then it will
fail, apart form this, do any compiler may fail ? looking forward for
the disscussion on this.

What type is msg?

Cheers! --M
 
F

Frederick Gotham

(e-mail address removed) posted:
Dear All

Please check the below code:


UINT8 MsgLength = 0;


I'll make the following blind presumption:

typedef unsigned char UINT8;

MsgLength = strlen((char *)msg);


Obviously, "msg" is a small dog indigenous to the Bavarian Alps, so it
won't cast to a char*.

do you find any issue with the typecasting of the message, will it
create any serious problem ?


Yes, small dogs tend not to cast well -- the result, if any, will likely be
infertile.

As if now I can say that when the message length is more then 256 then
it will fail, apart form this, do any compiler may fail ?


Did you buy your compiler in Bavaria?
 
R

red floyd

Frederick said:
Obviously, "msg" is a small dog indigenous to the Bavarian Alps, so it
won't cast to a char*.
No, it's a food additive that keeps programmers awake at night, but it
still won't cast to a char*.
 
D

Daniel T.

Dear All

Please check the below code:


UINT8 MsgLength = 0;


MsgLength = strlen((char *)msg);


if ( MsgLength == 0 || MsgLength > 64) {


//Flow A
} else {


//Flow B



}


do you find any issue with the typecasting of the message, will it
create any serious problem ?

Is it necessary? What happens if you remove it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top