Why when a string is defined as a constant the c compiler calls the lstrlen function? It knows its length at compile time. I don't understand.
Example :
static void Main_OnPaint(HWND hwnd)
{
PAINTSTRUCT ps;
RECT rc;
int _i = lstrlen("Hello, Windows!") ;
BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rc);
DrawText(ps.hdc, _T("Hello, Windows!"), -1, &rc, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
EndPaint(hwnd, &ps);
}
The asm code is :
lea rcx,[StringAdr]
call qword ptr [__imp_lstrlenA]
Is there an other way to compute a string length in that case.
I have strings as the following:
char str1[] = "String" ;
char str2[] = "\n"
"a file to \"generate\""
"%s\n" ;
From Pelle's help file :
6. Adjacent string literal tokens are concatenated into one string literal token ("abc" "def" becomes "abcdef").
An other question. In the previous code I have noticed that if a string exists more than once, it is created only once. Please confirm.