Behavior with primitive data types' value out of range & C99's PRI* macros
- by Yktula
Say we have an 8-bit unsigned integer n (UINT8_MAX=255); what is the behavior of the compiler for n=256? Where can I find a table of default behavior when the value of a data type is out of range for different data types? Is there a pattern to how they behave when set out of range?
#include <stdio.h>
#include <inttypes.h>
uint8_t n = UINT8_MAX;
int main() {
printf("%hhu ",n++);
printf("%hhu",n);
return 0;
}
Compiling with gcc -std=c99 -Wall *.c, this prints: 255 0
Also, is it acceptable to use C99's PRI* macros? How are they named?