I have a C program written for some embedded device in English. So there are codes like:
SomeMethod("Please select menu");
OtherMethod("Choice 1");
Say I want to support other languages, but I don't know how much memory I have with this device. I don't want to store strings in other memory areas where I might have less space and crash the program. So I want to store strings in the same memory area and take the same space. So I thought of this:
SomeMethod(SELECT_MENU);
OtherMethod(CHOICE_1);
And a separate header file:
English.h
#define SELECT_MENU "Please select menu"
#define CHOICE_1 "Choice 1"
For other languages:
French.h
#define SELECT_MENU "Text in french"
#define CHOICE_1 "same here"
Now depending which language I want I would include that header file only.
Does this satisfy the requirement that if I select English version my internationalized programs' strings
will be stored on same memory region and take same memory as my previous one? (I know French might take more - but that is other issue related that French letters take more bytes).
I thought since I will use defines
strings will be placed at same place in memory they were before.
The way you are doing that, if you compile the program as English, then French words will not be stored in the English version of the program.
The compiler will not even see the French words. The French words will not be in the final executable.
In some cases, the compiler may see some data, but it chooses to ignore that data if the data is not being used in the program.
For example, consider this function:
If you define this function, but you don't use it in the program, then the function
foo
and the string "qwerty" will not find their way in the final executable.Using macro doesn't make any difference. For example,
foo1
andfoo2
are identical.The data is stored in heap, heap limit is usually very large. There won't be shortage of memory unless
SOME_TEXT
is bigger than stack limit (usually about 100 kb) and this data is being copied in stack.So basically you don't have anything to worry about except the final size of the program.