0

I have a buffer where the first 4 bytes represents an unsigned 32bit integer. The buffer looks like this {32, 0, 0, 0, ...}

The following code works under gcc without any problems:

uint32_t size = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);

Size is 32 as expected but if i compile the project with msvc size is 538976288 instead of 32.

What is the problem?
EDIT: full source code for test:

#include <stdint.h>
#include <stdio.h>

int main()
{

    int pos = 0;
    uint32_t buffer [] = {32, 0, 0, 0};
    uint32_t size = buffer[pos++] | (buffer[pos++] << 8) | (buffer[pos++] << 16) | (buffer[pos++] << 24) ;
    printf("size=%d\n", size);
    return 0;
}
houssam
  • 1,823
  • 15
  • 27
NoFr1ends
  • 35
  • 1
  • 7

0 Answers0