Fetch the repository succeeded.
/*
* Copyright (C) 2014 Arjun Sreedharan
* License: GPL version 2 or higher http://www.gnu.org/licenses/gpl.html
*/
#include <stdio.h>
#include <assert.h>
void put_data(int*, unsigned int);
unsigned int get_data(unsigned int);
void cleanse_pointer(int*);
void put_data(int *p, unsigned int data)
{
assert(data < 4);
*p |= data;
}
unsigned int get_data(unsigned int p)
{
return (p & 3);
}
void cleanse_pointer(int *p)
{
*p &= ~3;
}
int main(void)
{
assert(sizeof(int) == 4);
assert(sizeof(void*) == 4);
unsigned int x = 701;
unsigned int p = (unsigned int) &x;
printf("Original ptr: %u\n", p);
put_data(&p, 3);
printf("ptr with data: %u\n", p);
printf("data stored in ptr: %u\n", get_data(p));
cleanse_pointer(&p);
printf("Cleansed ptr: %u\n", p);
printf("Dereferencing cleansed ptr: %u\n", *(int*)p);
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。