The following code executes as I would expect on gcc:
#include <inttypes.h>
#include <stdio.h>
int main(int argc, char **argv){
uint16_t apa = 10000;
uint16_t kaka = 7000;
uint32_t mazarin;
mazarin = apa*kaka;
printf("%lu \n",mazarin);
return 0;
}
I.e. it will print out the value 70000000. However, when I compile
this another compiler the result is truncated and I have to modify the
code to the following to make it run:
#include <inttypes.h>
#include <stdio.h>
int main(int argc, char **argv){
uint16_t apa = 10000;
uint16_t kaka = 7000;
uint32_t mazarin;
mazarin = (uint32_t)apa*kaka;
printf("%lu \n",mazarin);
return 0;
}
Could anybody explain this? Is this due to C99 improvements regarding
integer overflow? Is there any predefined macro one could use to
determine this special case?
(Note: The extended types in inttypes.h were added for the second
compiler.)
Regards
/Michael