length of char*

Started by
10 comments, last by krez 22 years, 5 months ago
Try this one.

int SizeOfChar(char* s)
{
char* ptr=s;
// continue while not null character
while(*s)
s++;

return s-ptr;
}
Friðrik Ásmundsson
Advertisement
  int strlen(const char* cszStr)	{	DWORD* p = (DWORD*) cszStr;	DWORD k,kk;		while(DWORD(p)&3)		{		if(*(char*)(p)==0)			return (char*)(p)-cszStr;		p = (DWORD*) (((char*)(p)) + 1);		}		do		{		k = *p;		kk = k + 0x7efefeff;		k ^= -1;		k ^= kk;		p++;		} while(!(k&0x81010100));		k = *(--p);	if(!(k&0x000000ff))		return (char*)(p)-cszStr;		if(!(k&0x0000ffff))		return (char*)(p)-cszStr+1;		if(!(k&0x00ff0000))		return (char*)(p)-cszStr+2;		if(!(k&0xff000000))		return (char*)(p)-cszStr+3;		return (char*)(p)-cszStr;	}  

Fastest one yet!

Magmai Kai Holmlor
- Not For Rent
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement