C语言设计新思维分享
生活随笔
收集整理的这篇文章主要介绍了
C语言设计新思维分享
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
没有任何套路,直接获取资源
C语言已经有几十年的历史了,经过长时间的发展和普及,C语言的应用场景也有了很大的变化,一些的老的观念已经不在适用,在这里给大家推荐一本讲C语言特别好的书,《C语言设计新思维》,没有任何套路直接下发领取。
C语言设计新思维
根据调用生成不同的函数
#define def_object_copy(tname, ...) \void * tname##_copy(tname *in) { \tname *out = malloc(sizeof(tname)); \*out = *in; \__VA_ARGS__; \return out; \} def_object_copy(keyval) // Expands to the previous declarations of keyval_copy. #include <stdio.h> #include <math.h> typedef struct point {double x, y; } point; typedef struct {//匿名结构体,定义之后相当于将原有的结构体成员直接放到这个地方struct point; ❶double z; } threepoint; double threelength (threepoint p){return sqrt(p.x*p.x + p.y*p.y + p.z*p.z); ❷ } int main(){threepoint p = {.x=3, .y=0, .z=4}; ❸printf("p is %g units from the origin\n", threelength(p)); }匿名联合体与匿名结构体的集合
/* Compile with: make LDLIBS='-lm' CFLAGS="-g -Wall -std=gnu11 -fms-extensions" seamlesstwo */ #include <stdio.h> #include <math.h>typedef struct point {double x, y; } point;typedef struct {union {struct point;point p2;};double z; } threepoint;double length (point p){return sqrt(p.x*p.x + p.y*p.y); }double threelength (threepoint p){return sqrt(p.x*p.x + p.y*p.y + p.z*p.z); }int main(){threepoint p = {.x=3, .y=0, .z=4};printf("p is %g units from the origin\n", threelength(p));double xylength = length(p.p2);printf("Its projection onto the XY plane is %g units from the origin\n", xylength); }如果不使用-fms-extensions标志,那么就是弱模式了。它不允许我
们使用匿名的结构标识符来引用我们以前定义过的结构,相反,它要求
结构必须在本地定义。这样,我们需要复制和粘贴整个P2 struct的定义
了。
总结
以上是生活随笔为你收集整理的C语言设计新思维分享的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 知识主题间先序关系挖掘
- 下一篇: 5G领域最权威绿宝书迎来中文版啦!