I have a string that I receive by serial and need to test the first 2 chars to take further action.
char buf[20]; ... if(buf[0]=='O' && buf[1]=='K') { ... }
I optimized it by converting to a word and compare the content to the ascii value of 4F (O) and 4B (K)
char buf[20]; ... if(*(uint16_t*)buf==0x4B4F) { ... }
I have a couple of test like this and it saves a lot of byte. It works well in my test too.
However it throws a
warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
I am using the atmel toolchain gcc version 4.7.2 (AVR_8_bit_GNU_Toolchain_3.4.2_939)
How can I remove this warning?