Casting problem?

Hi,

The compiler is returning a warning

192|warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]|

My buffer is a char array and I want to read 4 bytes into an unsigned int. I thought this code would work fine but the compiler is generating a warning

1
2
3
4
5
6
unsigned int Stream::readUInt()
{
    unsigned int i = *(int*)buffer[curBufPos];
    curBufPos+=4;
    return i;
}
note that (int*) is what is used in C programming.
although it valid syntax in C++ you explicitly choose what kind of casting you want ie:
unsigned int i = static_cast<unsigned int>(buffer[curBufPos]);

C is insecure because you it gives you a chance to introduce bugs.
anyway I don't understand why are you taking an address in your example?
My online game required a stream so I wrote a stream class. Their is a buffer that is allocated some space. I am adding all the security code before release .
Topic archived. No new replies allowed.