ARM Technical Support Knowledge Articles

FAQ How do I customize locales with C macros?

Applies to: RealView Development Suite (RVDS)


You can still use C macros in RVCT 3.1 to customize locales, but not in RVCT 4.0 and later versions. Header file <rt_locale.h> is required to define your own locales. In the library guide of RVCT 3.1, detailed information about each locale type is explained. Following is an example how to customize locales with C macros with RVCT 3.1:

#include <rt_locale.h>
#include <locale.h>
#include <stdio.h>

__LC_NUMERIC_DEF(lcnumeric_c, "C", ".", "", "")
__LC_NUMERIC_DEF(lcnumeric_iso8859_1, "ISO8859-1",
".", ",", "\3")
__LC_NUMERIC_DEF(lcnumeric_fr, "fr", ",", ".", "\3")

void const *_get_lc_numeric(void const *null, char const *name)
     return _findlocale(&lcnumeric_c_index, name);

void test_lc_numeric(void)
     double pi = 4*atan(1.);

     char * current_locale = setlocale(LC_NUMERIC, NULL); // Get current locale name
     if(current_locale != NULL)
          printf("current Numeric locale is : %s \n", current_locale);
     printf(" (1/1234567) = %f \n", 2.0/1234567.0+3456.23);
     printf("pi = %g \n",pi);

     current_locale = setlocale(LC_NUMERIC, "fr");
     if(current_locale != NULL)
          printf("current Numeric locale is : %s \n", current_locale);
     printf("(1/1234567) = %f \n",1.0/1234567.0+3456.23);
     printf("pi = %g \n",pi);

int main(void)
     return 0;
/*---------end of test.c----------*/

Building with command line:

    armcc test.c -o test.axf

and running test.axf on ARM7TDMI model, you should be able to see the results as following:

current Numeric locale is : C
(1/1234567) = 3456.230002
pi = 1.36005e+09

current Numeric locale is : fr
(1/1234567) = 3456,230001
pi = 1,36005e+09

1. Tailoring locale and CTYPE using C macros.
2. FAQ How do I customize locale with assembler macros?

Article last edited on: 2011-08-02 18:01:10

Rate this article

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 © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential