c++ - conversion to static_cast<unsigned char> -
does conversion like:
int a[3]; char i=1; a[ static_cast<unsigned char>(i) ]; introduce overhead conversions or can compiler optimize away? interested because want rid of -wchar-subscripts warnings, want use char index (other reasons)
i did 1 test on clang 3.4.1 code :
int ival(signed char c) { int a[] = {0,1,2,3,4,5,6,7,8,9}; unsigned char u = static_cast<unsigned char>(c); return a[u]; } here relevant part or assembly file generated c++ -s -o3
_z4ivala: # @_z4ivala # bb#0: pushl %ebp movl %esp, %ebp movzbl 8(%ebp), %eax movl .l_zz4ivalae1a(,%eax,4), %eax popl %ebp ret there no trace of conversion.
Comments
Post a Comment