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

Popular posts from this blog

php - Auto increment employee ID -

php - isset function not working properly -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -