gcc does merge string constants at all optimisation levels except -O0. Mingw should do likewise.
You can also add -fmerge-all-constants so it merges constant variables in addition to literals, but note that this is not standard conforming.
im not quite understand what you mean by string constants
they ale constants but i do not write a word const here
void DrawPixel(int x, int y, char* color)
{
if(color=="red") DrawPixel(x,y,0x00ff0000);
if(color=="blue") DrawPixel(x,y,0x000000ff);
}
I can change char* above to const char* but its a way to inform
compiler that "red" and "blue" in the body are also constants?
- i need youst this kind of code to work - on b55 & unity builds
(I didnt tried this with separate module strings there) it worked perfectly well (when turned -d "merge duplicate strings")
PS I tested it yet once (I tested before but a bit forgot the results)
when i use string literals in the same compiletion unit they are merged (sama adres) but when used in different compilation units
they are different (not merged) - and "-fmerge-constants -fmerge-all-constants" didnt help here I dont know why becouse I understand that it should
-fmerge-constants
Attempt to merge identical constants (string constants and floating-point constants) across compilation units.
still not sure how to understand by constants, all string literals are considered as a constants if im not wrong so they could be safely merged imo - but this do not work