- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
// endian dependend
#define PUT3(a,b,c) (((uint64_t)a<<8*0) | ((uint64_t)b<<8*1) | ((uint64_t)c<<8*2))
void testswitch(uint64_t x)
{
switch (x)
{
case PUT3('a','b','c'): printf("abc\n");
break;
case PUT3('d','e','f'): printf("def\n");
break;
case PUT3('g','h','i'): printf("ghi\n");
break;
default: printf("Choice other than abc, def and ghi\n");
break;
}
}
int main()
{
uint64_t x = 0;
char a[] = "abc";
memcpy(&x, a, sizeof(a)-1);
testswitch(x);
char b[] = "def";
memcpy(&x, b, sizeof(a)-1);
testswitch(x);
char c[] = "ghi";
memcpy(&x, c, sizeof(a)-1);
testswitch(x);
return 0;
}