Next: , Previous: libnix.a, Up: libnix.a


6.4.1 Locale

One feature of a complete ANSI compatible library is locale support. The ANSI standard only knows of two locales:

Every other locale depends very heavily on the implementation.

To do locale support on the amiga I decided to use locale.library (what else). This means that you normally have only these two locales - to have more than that you must make some extra preferences files with the locale preferences editor and give the path of these to the setlocale()-call. If you do not have locale.library you will get only "C" locale. This is the default then :-(.

Another important point is that the ANSI standard requires the default locale to be loaded at program startup. i.e. if you use german locale (for example) you will just get it - printf and scanf will not work as expected but use the decimal comma ‘,’ instead of the decimal point ‘.’ for their floating point numbers, ctype functions will behave differently, too.

This can be very annoying if you don't want to use ANSI locale but rather locale.library (which is not portable but IMHO much better) or if you don't need locale support. And even dangerous if you don't test your program under different locales.

To get around this problem I decided to do some nasty thing: To get locale support you have to make up a reference to setlocale. You can do this by just calling

setlocale(LC_ALL,"C");

immediately after program startup. (And get "C" locale then after program start which is a much better choice). Or by just using setlocale anywhere in your program - you will get default locale at program startup then.