C语言设计新思维分享

没有任何套路,直接获取资源
C语言已经有几十年的历史了,经过长时间的发展和普及,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的定义
了。

typedef struct {
union {
	struct {
			double x, y;
		};
	point p2;
	};
	double z;
} threepoint;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

andrewbytecoder

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值