Doubt cast with pointer

5
 while( ++idx <= fp_size)
 {  
     byte current = buff[idx];
     int integer = 0 ; 
     short shortint = 0 ; 

     if(idx < fp_size - 3)
         integer = *((int *))&buff[idx];
 }

What kind of cast is this *((int *)) ? variable integer is of type int is buff unsigned char .

    
asked by anonymous 06.10.2015 / 00:00

1 answer

6

Cast is only (int *) . The rest is reference and reference.

What happens on this line is as follows:

First, we get the address of an element of the vector buff : &buff[idx] . If buff is of type unsigned char , a unsigned char * will be returned.

Once this is done, a cast of unsigned char* is done to int* : (int *) .

Finally, a redo is done in * , returning a int .

The variable int will contain the following values in its bytes:

buff[idx]
buff[idx + 1]
buff[idx + 2]
buff[idx + 3]

That's if endianness of your machine is little endiann . If big endiann , it will be the reverse order.

    
06.10.2015 / 03:19