Created
December 1, 2019 05:35
-
-
Save joaoantoniocardoso/87e00c47f94a4ed987c6da9754340844 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void type1(void); | |
void type2(void); | |
void type3(void); | |
void type4(void); | |
// CFlags for avr-gcc: | |
// -mmcu=atmega328p -DF_CPU=16000000UL -Os -funsigned-char -funsigned-bitfields | |
// -fpack-struct -fshort-enums -Wall -Wundef -MMD -MP | |
// avr-gcc 5.4.0: https://godbolt.org/z/vwbK4A | |
// avr-gcc 9.2.0: https://godbolt.org/z/CX9X2a | |
void type1(void) | |
{ | |
int i; | |
printf("\n>>> Type 1: if(counter++ >= counter_max){...}"); | |
for(i = 8; i; i--){ | |
const unsigned char counter_max = 4; | |
static unsigned char counter = 0; | |
printf("\n%d", counter); | |
if(counter++ >= counter_max-1){ | |
counter = 0; | |
printf("-> IN"); | |
} | |
} | |
} | |
// avr-gcc 5.4.0: https://godbolt.org/z/fg-FM5 | |
// avr-gcc 9.2.0: https://godbolt.org/z/bQRP2E | |
void type2(void) | |
{ | |
int i; | |
printf("\n>>> Type 2: if(++counter == counter_max){...}"); | |
for(i = 8; i; i--){ | |
const unsigned char counter_max = 4; | |
static unsigned char counter = 0; | |
printf("\n%d", counter); | |
if(++counter == counter_max){ | |
counter = 0; | |
printf("-> IN"); | |
} | |
} | |
} | |
// avr-gcc 5.4.0: https://godbolt.org/z/_2zqR7 | |
// avr-gcc 9.2.0: https://godbolt.org/z/evWgJD | |
void type3(void) | |
{ | |
int i; | |
printf("\n>>> Type 3: if(!counter--){...}"); | |
for(i = 8; i; i--){ | |
const unsigned char counter_max = 4; | |
static unsigned char counter = counter_max-1; | |
printf("\n%d", counter); | |
if(!counter--){ | |
counter = counter_max-1; | |
printf("-> IN"); | |
} | |
} | |
} | |
// avr-gcc 5.4.0: https://godbolt.org/z/XeXQmM | |
// avr-gcc 9.2.0: https://godbolt.org/z/ck7tzN | |
void type4(void) | |
{ | |
int i; | |
printf("\n>>> Type 4: if(!--counter){...}"); | |
for(i = 8; i; i--){ | |
const unsigned char counter_max = 4; | |
static unsigned char counter = counter_max; | |
printf("\n%d", counter); | |
if(!--counter){ | |
counter = counter_max; | |
printf("-> IN"); | |
} | |
} | |
} | |
int main(void) | |
{ | |
type1(); | |
type2(); | |
type3(); | |
type4(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment