typedef 摘自百度百科
|
1
|
typedef long byte_4; |
|
1
2
3
4
5
6
7
8
9
10
|
typedef struct tagMyStruct{int iNum;long lLength;}MyStruct; |
|
1
2
3
4
5
6
7
8
9
10
|
struct tagMyStruct{int iNum;long lLength;}; |
|
1
2
3
4
5
6
7
8
9
10
|
typedef struct tagNode{char* pItem;struct tagNode* pNext;}*pNode; |
|
1
2
3
4
5
6
7
8
9
10
|
typedef struct tagNode* pNode;struct tagNode{char* pItem;pNode pNext;//这边不用pNode* ,pNode 已经表示了struct tagNode*}; |
|
1
2
3
4
5
6
7
8
9
|
struct tagNode{char* pItem;struct tagNode* pNext;};typedef struct tagNode* pNode; |
|
1
2
3
|
typedef char* pStr;#define pStr char* |
|
1
2
3
4
5
6
7
|
typedef char* pStr1;#define pStr2 char* pStr1 s1,s2;pStr2 s3,s4; |
|
1
2
3
4
5
6
7
8
9
|
#include <stdio.h>#define f(x) x*xint main(void){ int a=6, b=2, c; c = f(a) / f(b); printf("%d\n", c); return 0;} |
|
1
|
#definef(x)((x)*(x)) |
|
1
2
3
4
5
6
|
typedef char *pStr;char string[4]="abc";const char *p1=string;const pStr p2=string;p1++;p2++; |
从变量名看起,先往右,再往左,碰到一个圆括号就调转阅读的方向;括号内分析完就跳出括号,还是按先右后左的顺序,如此循环,直到整个声明分析完。举例:
int (*func)(int *p);
首 先找到变量名func,外面有一对圆括号,而且左边是一个*号,这说明func是一个指针;然后跳出这个圆括号,先看右边,又遇到圆括号,这说明 (*func)是一个函数,所以func是一个指向这类函数的指针,即函数指针,这类函数具有int*类型的形参,返回值类型是int。
int (*func[5])(int *);
func 右边是一个[]运算符,说明func是具有5个元素的数组;func的左边有一个*,说明func的元素是指针(注意这里的*不是修饰func,而是修饰 func[5]的,原因是[]运算符优先级比*高,func先跟[]结合)。跳出这个括号,看右边,又遇到圆括号,说明func数组的元素是函数类型的指 针,它指向的函数具有int*类型的形参,返回值类型为int。
1.常规变量类型定义
例如:typedef unsigned char uchar
描述:uchar等价于unsigned char类型定义 uchar c声明等于unsigned char c声明
2.数组类型定义
例如: typedef int array[2];
描述: array等价于 int [2]定义; array a声明等价于int a[2]声明
扩展: typedef int array[M][N];
描述: array等价于 int [M][N]定义; array a声明等价于int a[M][N]声明
3.指针类型定义
例如: typedef int *pointer;
描述: pointer等价于 int *定义;pointer p声明等价于int *a声明
例如: typedef int *pointer[M];
描述: pointer等价于 int *[M]定义 pointer p声明等价于int *a[M]声明明
4.函数地址说明
描述:C把函数名字当做函数的首地址来对待,我们可以使用最简单的方法得到函数地址
例如: 函数:int func(void); unsigned long funcAddr=(unsigned long)func, funcAddr的值是func函数的首地址
5.函数声明
例如: typedef int func(void); func等价于 int (void)类型函数
描述1: func f声明等价于 int f(void)声明,用于文件的函数声明
描述2: func *pf声明等价于 int (*pf)(void)声明,用于函数指针的生命,见下一条
6.函数指针
例如: typedef int (*func)(void)
描述: func等价于int (*)(void)类型
func pf等价于int (*pf)(void)声明,pf是一个函数指针变量
7.识别typedef的方法:
a).第一步。使用已知的类型定义替代typdef后面的名称,直到只剩下一个名字不识别为正确
如typedef u32 (*func)(u8);
从上面的定义中找到 typedef __u32 u32;typedef __u8 u8
继续找到 typedef unsigned int __u32;typedef unsigned char __u8;
替代位置名称 typedef unsigned int (*func)(void);
现在只有func属于未知。
b).第二步.未知名字为定义类型,类型为取出名称和typedef的所有部分,如上为
func等价于unsigned unsigned int (*)(unsigned char);
c).第三部.定义一个变量时,变量类型等价于把变量替代未知名字的位置所得到的类型
func f等价于unsigned unsigned int (*f)(unsigned char)
代码简化
typedef 摘自百度百科的更多相关文章
- #ifndef -摘自百度百科
#ifndef 标识1 //判断"标识1"是否定义,如果被定义则返回假,如果没有被定义则返回真. /**********************************/ 语句1 ...
- LPCTSTR —— 摘自百度百科
LPCTSTR用来表示字符是否使用UNICODE. 如果程序定义了UNICODE或者其他相关的宏,那么这个字符或者字符串将被作为UNICODE字符串,否则就是标准的ANSI字符串. 类型理解:L,表示 ...
- python爬虫—爬取百度百科数据
爬虫框架:开发平台 centos6.7 根据慕课网爬虫教程编写代码 片区百度百科url,标题,内容 分为4个模块:html_downloader.py 下载器 html_outputer.py 爬取数 ...
- [Python爬虫] Selenium获取百度百科旅游景点的InfoBox消息盒
前面我讲述过如何通过BeautifulSoup获取维基百科的消息盒,同样可以通过Spider获取网站内容,最近学习了Selenium+Phantomjs后,准备利用它们获取百度百科的旅游景点消息盒(I ...
- Python3爬取百度百科(配合PHP)
用PHP写了一个网页,可以获取百度百科词条.源代码已分享至github:https://github.com/1049451037/xiaobaike/tree/master 那么通过Python来爬 ...
- redis百度百科和维基百科知识总结:
1. 百度百科知识总结: Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15日起,Redis ...
- Apache Mesos_百度百科
Apache Mesos_百度百科 Apache Mesos
- JEFF BANKS_百度百科
JEFF BANKS_百度百科 JEFF BANKS
- RCMTM _百度百科
RCMTM _百度百科 RCMTM
随机推荐
- utf8的大小写敏感性测试及其修改方法
utf8的大小写敏感性测试及其修改方法 # 测试utf8的大小写敏感性及其修改方法 -- 以下是utf8不区分大小写 # 修改数据库: ALTER DATABASE database_name CHA ...
- bootstrap浅谈
学习地址:http://www.runoob.com/bootstrap/bootstrap-tutorial.html 自己练习了下 主要是使用了bootstrap中包含的class类样式,只要给相 ...
- 【ASP.NET】website转webapplication
*以下操作都以VS2013为参考: #新建两种web项目 1.添加webapplication项目: 2.添加website项目: #比较两种web项目新建的webform页面的不同点: 1.文件目录 ...
- Linux性能优化实战:系统的swap变高(08)
一.Swap 原理 前面提到,Swap 说白了就是把一块磁盘空间或者一个本地文件(以下讲解以磁盘为例),当成内存来使用.它包括换出和换入两个过程 1.所谓换出 就是把进程暂时不用的内存数据存储到磁盘中 ...
- SpringBoot项目@RestController使用 redirect 重定向无效
Spring MVC项目中页面重定向一般使用return "redirect:/other/controller/";即可. 而Spring Boot当我们使用了@RestCont ...
- Linux记录-open-falcon开源监控系统部署
参考https://book.open-falcon.org/zh_0_2/quick_install/prepare.html一.安装后端1.环境准备yum -y install redisyum ...
- CSS盒模型(Box Model)
阅读目录 1. 什么是CSS盒模型 2. IE盒模型和W3C盒模型 3. CSS3属性box-sizing 4. 关于盒模型的使用 在最初接触CSS的时候,对于CSS盒模型的不了解,撞了很多次的南墙呀 ...
- Vue.js 技术揭秘(学习) vue流程
new Vue() _init() mergeOptions $watch --> new Watch vm._render 生成VNode create diff patch vm._upda ...
- Leetcode#88. Merge Sorted Array(合并两个有序数组)
题目描述 给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组. 说明: 初始化 nums1 和 nums2 的元素数量分别为 m ...
- Java同步容器
一.为什么会出现同步容器 Java的集合框架中,主要有四大类别:List,Set,Queue,Map List,Set,Queue接口分别继承了Collection接口,Map本身是一个接口. 注意C ...