ARM Technical Support Knowledge Articles

C library character and string function problems

Applies to: ARM Developer Suite (ADS), RealView Developer Kit (RVDK) for OKI, RealView Developer Kit (RVDK) for ST, RealView Developer Kit for XScale (RVXDK), RealView Development Suite (RVDS), Software Development Toolkit (SDT)

If you encounter problems at runtime with the C library character handling functions from ctype.h,
e.g. isdigit()toupper()tolower()
or string conversion functions from stdlib.h,
e.g. atoi()atof()
or string i/o functions,
e.g. sscanf() and sprintf()
this normally arises because the locale has not been correctly initialized or it is being accidentally overwritten at runtime.

A typical problem might be when the call isdigit('1') returns 0 rather than 1.

Most cases of such behaviour are caused by bypassing the C library standard initialization code, e.g., by providing your own __main() function. The best solution to this is to ensure that the C library's initialization code in __rt_lib_init() is called correctly. This will setup locale, and any other C library functions which need to be initialized, automatically.

Alternatively you may be able to work around the problem by using:

  #include <locale.h>
  setlocale(LC_ALL,"C");

However this is not recommended, especially as this will pull in additional parts of locale which may not be needed in your system (potentially around 1.4KB extra). It also leaves the possibility of other parts of the C library remaining uninitialized which may lead to later problems.

Article last edited on: 2009-07-07 16:53:16

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2008-9 ARM Limited. All rights reserved. External (Open), Non-Confidential