Marvee Amasi
Marvee Amasi
DIIDevHeads IoT Integration Server
Created by Marvee Amasi on 6/27/2024 in #middleware-and-os
Are there any specific considerations for MSVC to avoid unexpected truncation during such conversion
Here is the code from the editor :
#include <stdio.h>

double getDouble() {
double value = 2147483649.0;
return value;
}

int main() {
unsigned int directCast;
double d;

printf("INT_MAX: %u\n", INT_MAX);
printf("UINT_MAX: %u\n", UINT_MAX);

printf("Double value: %f\n", getDouble());

directCast = (unsigned int)getDouble();
printf("Direct cast value: %u\n", directCast);

d = getDouble();
printf("Indirect cast value: %u\n", (unsigned int)d);

return 0;
}
#include <stdio.h>

double getDouble() {
double value = 2147483649.0;
return value;
}

int main() {
unsigned int directCast;
double d;

printf("INT_MAX: %u\n", INT_MAX);
printf("UINT_MAX: %u\n", UINT_MAX);

printf("Double value: %f\n", getDouble());

directCast = (unsigned int)getDouble();
printf("Direct cast value: %u\n", directCast);

d = getDouble();
printf("Indirect cast value: %u\n", (unsigned int)d);

return 0;
}
3 replies