Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- * Compares two methods of testing bit 5
- * Clarify compiler behaviour for stackoverflow.com topic 9767686
- *
- * main.c
- *
- * Created by G Bulmer on 19/03/2012.
- */
- #include "dummy_printf.h" // get rid of stdio.h
- #include "original_bit5.h"
- #include "my_bit5.h"
- int main (int argc, const char * argv[]) {
- int number = 16;
- original_bit5(number);
- my_bit5(number);
- return 0;
- }
- /***
- * original_bit5.c
- */
- #include "dummy_printf.h" // get rid of stdio.h
- #include "original_bit5.h"
- void original_bit5(int number) {
- int mask = 1<<5;
- if ((number & mask) == 0)
- dummy_printf("Bit is off");
- else
- dummy_printf("its on");
- }
- /***
- * my_bit5.c
- */
- #include "dummy_printf.h" // get rid of stdio.h
- #include "my_bit5.h"
- void my_bit5(int number) {
- dummy_printf((number & 0x20)?"its on":"Bit is off");
- }
- /***
- * dummy_printf.c
- */
- #include "dummy_printf.h"
- void dummy_printf(const char* str) {
- const volatile const char* port = (const char*)0x20000000;
- port = str; // stop the compiler throwing anything away
- }
- /***
- * dummy_printf.h
- */
- #ifndef _DUMMY_PRINTF_H_
- #define _DUMMY_PRINTF_H_
- void dummy_printf(const char* str);
- #endif
- /***
- * original_bit5.h
- */
- #ifndef _ORIGINAL_BIT5_H_
- #define _ORIGINAL_BIT5_H_
- extern void original_bit5(int number);
- #endif
- /***
- * my_bit5.h
- */
- #ifndef _MY_BIT5_H_
- #define _MY_BIT5_H_
- extern void my_bit5(int number);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement