void指针强转结构体指针问题
来源:互联网 发布:我的校园软件 编辑:程序博客网 时间:2024/06/07 22:37
====================================================================================================================================
1.程序,test.c
#include <stdio.h>#include <stdlib.h>typedef unsigned long u32; //64位机器为8字节,32位机器为4字节typedef struct my_struct{ u32 a; u32 b; u32 c;}mystruct;int main(){ void *test; test = NULL; test = malloc(1); printf("test is %lx\n",test); #define GPIO ((mystruct *)(test)) GPIO->a = 10; GPIO->b = 20; GPIO->c = 30; printf("(&(GPIO->a)) is %lx\n",(&(GPIO->a))); printf("(&(GPIO->b)) is %lx\n",(&(GPIO->b))); printf("(&(GPIO->c)) is %lx\n",(&(GPIO->c))); printf("GPIO->a is %d\n",GPIO->a); printf("GPIO->b is %d\n",GPIO->b); printf("GPIO->c is %d\n",GPIO->c); free(test); test = NULL; return 0;}2.编译gcc -o test test.cpp,我的机器是64位ubuntu。
3.结果./test
test is 17f2010(&(GPIO->a)) is 17f2010(&(GPIO->b)) is 17f2018(&(GPIO->c)) is 17f2020GPIO->a is 10GPIO->b is 20GPIO->c is 30
- void指针强转结构体指针问题
- void指针强转结构体指针问题
- void* unknown size问题及结构体转指针问题
- 复习6:void指针和结构体
- void 指针问题
- 结构体指针问题
- 结构体指针问题
- 【转】关于void指针
- 结构体指针移位问题~~
- 关于结构体指针问题
- 结构体指针初始化问题
- void指针
- void指针
- void指针
- void指针。。。
- void指针
- void* 指针
- void指针
- git/github学习笔记
- java多个pdf合成一个pdf
- Windows Server 2003 R2 系统服务
- 录制caf转mp3
- Android Zipalign工具
- void指针强转结构体指针问题
- cocoa ios iphone xcode 播放GIF动画
- phpcms头条图片
- ColorMatrix
- Android Intent Flag的介绍
- 基础要点总结
- 使用dma_alloc_writecombine申请内存空间大小的限制
- linux softirq和tasklet的关系
- Android APK签名流程