누구라곤 말 안하겠습니다.


size_t strlen_ex(const char* str)

{

size_t *u32 = (size_t*)str, u, abcd, i = 0;

while (true)

{

u = u32[i++];

abcd = (u - 0x01010101) & 0x80808080;


if (abcd && // If abcd is not 0, we have NUL or a non-ASCII char > 127...

(abcd &= ~u)) // ... Discard non-ASCII chars

return 4 * i - (abcd & 0xffff0000 ? (abcd & 0xff000000 ? 1 : 2) : abcd & 0xff00 ? 3 : 4);

}

}



int main()

{

//초기화 되지 않은 메모리 할당

char *temp = (char*)malloc(STRLEN);

for (int i = 0; i < LEN; ++i)

{

temp[i] = i % 255 + 1;



#if 1

// 검증

temp[i + 1] = 0;

if (strlen(temp) != strlen_ex(temp))

{

printf("length error %d %d\n", strlen(temp), strlen_ex(temp));

printf("string %s\n", temp);

system("pause");

}

#endif // 1

}


temp[LEN] = 0;

}



결과


length error    4 11

string