EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Force IAR to use char inside of int for convert %d in sscanf

Started by Nader March 20, 2008
I want use something like this:
char TempIP[4];

if(sscanf(&console_str[2+1],"d.%d.d.%d",&TempIP[0],&TempIP[4],&TempIP[8],&TempIP[12])
== 4){
// do something
}
but IAR use only int to conver %d. In 8 bit cpu it work well but in
ARM7 core should use extera RAM.
is there any way to force IAR to use char inside of int for convert %d
in sscanf?

Thanks.

An Engineer's Guide to the LPC2100 Series

Nader schrieb:
> I want use something like this:
> char TempIP[4];
>
> if(sscanf(&console_str[2+1],"d.%d.d.%d",&TempIP[0],&TempIP[4],&TempIP[8],&TempIP[12])
> == 4){
> // do something
> }
> but IAR use only int to conver %d. In 8 bit cpu it work well but in
> ARM7 core should use extera RAM.
> is there any way to force IAR to use char inside of int for convert %d
> in sscanf?

%d == int == 32 bit on ARM.

What you are intend to do is very very error prone.
I would not recommend sscanf(). What do you expect as user-inpit ?
Maybe atoi() does a better job.

--
42Bastian

Note: SPAM-only account, direct mail to bs42@...

=======================================================================Groups related to lpc2000
=======================================================================
msp430 (388 common members)
http://groups.yahoo.com/group/msp430?v=1&t=ipt&ch=email&pub=groups&slktr0&sec=recg
Computers & Internet/Hardware: Welcome to the MSP430 User's Group! The purpose of...

AVR-Chat (177 common members)
http://groups.yahoo.com/group/AVR-Chat?v=1&t=ipt&ch=email&pub=groups&slktr1&sec=recg
Microprocessors/Microcontrollers: A place for Atmel AVR Microcontroller users to sha...

LTspice (165 common members)
http://groups.yahoo.com/group/LTspice?v=1&t=ipt&ch=email&pub=groups&slktr2&sec=recg
Engineering/Electrical: Dedicated to the exchange of information about LTs...

Homebrew_PCBs (157 common members)
http://groups.yahoo.com/group/Homebrew_PCBs?v=1&t=ipt&ch=email&pub=groups&slktr3&sec=recg
Engineering/Electrical: Designing, making, etching, soldering, printed cir...

e-embedded (151 common members)
http://groups.yahoo.com/group/e-embedded?v=1&t=ipt&ch=email&pub=groups&slktr4&sec=recg
Internet/Internet Appliances: Open-membership mailing list for embedded system d...
Nader Wrote
>I want use something like this:
>char TempIP[4];
>
>if(sscanf(&console_str[2+1],"d.%d.d.%d",&TempIP[0],&TempIP[4],&TempIP[8],&T
empIP[12])
>== 4){
> // do something
>}
>but IAR use only int to conver %d.

Of course.

>In 8 bit cpu it work well

Only if the compiler is non-standard. I've worked with ones that are
standard that would fail on your code as well. Admittedly a number of
compilers for 8 bit processors are broken in this regard.

What you have written is wrong even if the type sizes match (they could
legitimately if chars were 16bits in size or larger). I'll not mention you
are converting into non-existent array elements. Oops ;)

>but in
>ARM7 core should use extera RAM.

You likely have more ram to begin with anyway. Probably far more if you
are used to a compiler treating ints as if they were 8 bits.

>is there any way to force IAR to use char inside of int for convert %d
>in sscanf?

I would be surprised if there were.

Two ways to solve your problem

1) Don't use the ...scanf family. It's not really suited for a lot of
embedded work anyway. Make a simple ascii to integer conversion function
of your own and feed it the subset of the string you want to convert.

2) The quick and dirty approach which is quite legitimate for some
applications. Use scanf as you are with tempIP as a local int array and
add a copy to copy the scanned ints into a more permanent char storage. If
you are using scanf storage cannot really be a big concern of yours anyway
;)

Robert

--------------------------------
mail2web - Check your email from the web at
http://link.mail2web.com/mail2web

=======================================================================Groups related to lpc2000
=======================================================================
msp430 (388 common members)
http://groups.yahoo.com/group/msp430?v=1&t=ipt&ch=email&pub=groups&slktr0&sec=recg
Computers & Internet/Hardware: Welcome to the MSP430 User's Group! The purpose of...

AVR-Chat (177 common members)
http://groups.yahoo.com/group/AVR-Chat?v=1&t=ipt&ch=email&pub=groups&slktr1&sec=recg
Microprocessors/Microcontrollers: A place for Atmel AVR Microcontroller users to sha...

LTspice (165 common members)
http://groups.yahoo.com/group/LTspice?v=1&t=ipt&ch=email&pub=groups&slktr2&sec=recg
Engineering/Electrical: Dedicated to the exchange of information about LTs...

Homebrew_PCBs (157 common members)
http://groups.yahoo.com/group/Homebrew_PCBs?v=1&t=ipt&ch=email&pub=groups&slktr3&sec=recg
Engineering/Electrical: Designing, making, etching, soldering, printed cir...

e-embedded (151 common members)
http://groups.yahoo.com/group/e-embedded?v=1&t=ipt&ch=email&pub=groups&slktr4&sec=recg
Internet/Internet Appliances: Open-membership mailing list for embedded system d...

The 2024 Embedded Online Conference