Casting cost addressing pointer in c from unsigned char * to const char *? -
i wondering how many there calculating @ compile casting of addressing.
e. g.
in strlen
api defined :
size_t strlen ( const char * str );
they arr const char *
.
but sometime use
unsigned char arr[] = "something" strlen((const char *)arr);
just focus on unsigned char *
const char *
i wonder cost there in code?
there no runtime overhead associated cast in way. merely tells compiler access (or interpret) variable differently how declared.
in specific case, compiler smart enough generate code treats char
array char*
pointer no overhead.
in general, casts in c never incur runtime overhead.
Comments
Post a Comment