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领域最权威绿宝书迎来中文版啦!