Legacy sscanf function doesn’t work under MQX using %u.

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

Legacy sscanf function doesn’t work under MQX using %u.

2,601 Views
juanee
Contributor III

Hello All,

 

I was trying to get the following to work :

 

//Local Variablesvolatile char input_string[]= "123456789012345678901234567890";volatile uint_16 i=0, number_sscanf=0;volatile uint_8 arg1=0, arg2=0, arg3=0;{..number_sscanf = sscanf (input_string, "%s %u %u %u",command_string1, &arg1, &arg2, &arg3);..}

 

I later found out doing research on this forum that:

 

a.  I have to use %i instead of %u

b.  I have to declare my arg variables uint_32 instead of uint_8

c.  I cannot use “volatile char input_string[] = …”, I have to declare it as “char input_string[] = …”

 

I found my answer here:

https://community.freescale.com/message/47264#47264

 

My questions:

 

1.  How come MQX does not support a legacy function fully like sscanf?

 

2.  The MQX sscanf function has limitations, so why isn’t it well documented somewhere?  I found inside io_scanf.c to see scanline.c for comments, but I couldn’t find the file.  (In contrast, the MSL_C_Reference.pdf included with Codewarrior Coldfire [when not using MQX] seems to conform to C99 and is well documented).

 

If I am wrong in anything above, please let me know.

 

Juanee

 

(I am using Codewarrior 7.1.2 for Coldfire (MCF52259 target), MQX 3.5).

 

 

0 Kudos
Reply
4 Replies

1,051 Views
CompilerGuru
NXP Employee
NXP Employee

I don't know MQX, so just for the ANSI C part.

For %u or %i using a int (or unsigned int) type is required. Using a 8 bit variable is undefined behavior.

Also implicitly loosing volatile seems seems wrong to me. However a full ANSI-c version should support %u, of course.


Daniel

1,051 Views
juanee
Contributor III

Thank you for your reply CompilerGuru

 

Interesting.  My ANSI C book reference I use has an example using int (like you said is required), but it doesn't say I can't use something else, like an 8 bit unsigned int.

 

Do you have a reference you can recommend (a book or a web link) where it specifically specifies what I can or cannot use for legacy functions such as sscanf using ANSI C? 

 

juan 

0 Kudos
Reply

1,051 Views
kecart
Contributor III

I can't suggest a book, but I would suggest you look at the source code for _io_scanline in the file io_scanl.c.  There you will find exactly what MQX does support.  You just can't beat having the source code available to gain a better understanding of what is happening behind the scenes in you firmware.  Tell the guys at Freescale how much you appreciate this level of software support.  I understand they spent quite a chunk of change getting the rights to distribute MQX.

0 Kudos
Reply

1,051 Views
juanee
Contributor III

I will take a look at the scanline MQX code you suggested.  Thank you for your recommendation kecart.

 

juanee

0 Kudos
Reply