누구라곤 말 안하겠습니다.
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
#define LEN 99999#define STRLEN (LEN+1)
글 수정이 안되넹
그러면 김치 국물에 국수를 말아서?!
후루룩~
x64에서 uint32_t != size_t는 사이즈가 달라서 다시 테스트 해보았지만 역시나 똑같이 에러네요.
바꾸고 해도 에러라구요