This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
typed cast's
This has nothing to do with optimization.
This has something to do with the parser.
In C you can convert an expression of (nearly) any type to another type.
float f = (float) (&f);
Typecasting is dangerous. But sometimes you need typecasting.
Often you want to cast type A to type B.
C has only the possibity to cast any type to type B.
int x [128];
float f [128];
// p is a char*, but can also work with int-data from x, but never can work with float data)
char* p = (char*) x; // dangerous
char* p = (char*) f; // bug, but C can't determine that
char* q = (char*,int*) x; // explicit convering from int* to char*
char* q = (char*,int*) f; // compile time error
Especially if you are using macros this can be useful to determine bugs as
early as possible.
Syntax:
(dest_type)
(dest_type,allowed_src_type)
(dest_type,allowed_src_type1,allowed_src_type2)
(dest_type,allowed_src_type1,allowed_src_type2,allowed_src_type3)
etc.
Examples:
(size_t,int)-1
(void*,int)0
*p++ = (uint8_t,uint32_t)(word32 >> 8);
*p++ = (int,unsigned int) Bitstream_read (Res_bit[Res[Band].R]) - Dc[Res[Band].R];
--
Frank Klemm