C
ccwork
Hi all,
Is the following codes Standard C?
unsigned long number = ULONG_MAX;
unsigned long result = 0;
result = (unsigned long) number % ULONG_MAX;
printf("ULONG_MAX=%lu, number=%lu, result=%lu\n", ULONG_MAX, number,
result);
My compiler (VC++ if you want to know), in debug mode, give:
ULONG_MAX=4294967295, number3=4294967295, result3=0
However, in release mode, it gives:
ULONG_MAX=4294967295, number3=4294967295, result3=4294967295
I don't know if the code trigger undefined behaviour or it is the
compiler bug.
Is the following codes Standard C?
unsigned long number = ULONG_MAX;
unsigned long result = 0;
result = (unsigned long) number % ULONG_MAX;
printf("ULONG_MAX=%lu, number=%lu, result=%lu\n", ULONG_MAX, number,
result);
My compiler (VC++ if you want to know), in debug mode, give:
ULONG_MAX=4294967295, number3=4294967295, result3=0
However, in release mode, it gives:
ULONG_MAX=4294967295, number3=4294967295, result3=4294967295
I don't know if the code trigger undefined behaviour or it is the
compiler bug.