Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
uint8_t event1(int32_t* param) {
uint8_t data = (uint8_t)*param;
printf("%"PRId8"\n", data);
}
uint8_t event2(int32_t* param) {
uint8_t data = *(uint8_t*)param;
printf("%"PRId8"\n", data);
}
int main(int argc, char* argv[]) {
uint8_t data = 96;
int32_t param1 = (int32_t)data;
int32_t param2 = 0xdeadbeef; // 検証のために適当に値を埋めておく
*( (uint8_t*)&param2 ) = data;
// 正しい使い方
event1(&param1);
event2(&param2);
// 誤った使い方
event1(&param2);
event2(&param1);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment