c
文章平均质量分 54
tzshlyt
不积跬步,无以至千里。
展开
-
c 语言函数指针和高级语言闭包区别
高阶函数所谓高阶函数,就是用函数作为参数的函数。函数指针typedef void (*func_t)(int);void foreach(struct node *list, func_t func) { while (list) { func(list->val); list = list->next; }}void f(int n) { printf("node(?) = %d\n", n);}int main() { st原创 2021-03-11 16:35:03 · 943 阅读 · 0 评论 -
c语言可变参数函数的原理与实现详解
c 语言可变参数函数的原理与实现详解上代码,注意此代码运行在 32 位系统上,所以下文的数据类型大小按32位计算。#include <stdio.h>#include <stdarg.h>// 模仿 printf 函数可变参数的样式void f(const char *fmt, ...) { // 模仿获取可变参数的获取过程 char *ap; ap = (char *)&fmt; // ap 为第一个参数的地址 int v1原创 2020-05-23 17:56:10 · 490 阅读 · 0 评论 -
汇编 hello 程序 的学习
.datamsg: .ascii "hello \n" # 打印字符串,末尾没有隐 含的'\0'len = . - msg # 字符串长度,“. ”代表当前地址计数器的值.text.global _start_start: movl $len, %edx # 分布是 write 系统调用的3个参数 movl $msg...原创 2019-07-02 16:04:35 · 444 阅读 · 0 评论 -
使用回调函数实现类型c++的泛型算法
max 函数可以在任意一组对象中找出最大值,实现者并不知道怎样去比较两个对象的大小,调用者需要提供一个做比较操作的回调函数。// generics.h#ifndef GENERICS_H#define GENERICS_Htypedef int (*cmp_t)(void *, void *);extern void *max(void *data[], int num, cmp原创 2016-11-01 10:17:27 · 897 阅读 · 0 评论 -
一个Linux下c语言线程池的实现
#include "threadpool.h"#include "common.h"threadpool_t *threadpool_init(int thread_num, int queue_max_num){ threadpool_t *pool = NULL; pool = malloc(sizeof(threadpool_t)); do {原创 2017-07-06 22:06:48 · 853 阅读 · 0 评论 -
使用回调实现对一组任意类型的对象做快速排序
qsort函数实现对一组任意类型对象的排序,调用者提供 findPos_t 回调函数,在回调函数中实现对特定类型元素位置的查// qsort.h#ifndef QSORT_H#define QSORT_Htypedef int (*findPos_t)(void *a[], int left, int right);extern void qsort(void *a[], int l原创 2016-11-01 15:02:19 · 402 阅读 · 0 评论 -
c语言每隔1秒向文件中写入一行记录,类似日志记录
读写一个文件test.txt,每隔1秒向文件中写入一行记录,直到按Ctrl-C终止。下次启动程序时在test.txt文件末尾追加记录,并且序号能够接续上次的序号。#include #include #include #include #include int main(void) { FILE *fp; fp = fopen("test.txt", "a+");原创 2016-11-03 16:01:58 · 5909 阅读 · 0 评论 -
c 语言变量的存储布局 笔记
1、源代码 main.c#include const int A = 10; // GLOBAL的符号 //const表示只读,不可修改, 分配在.rodata //程序加载运行时,.rodata 段和 .text 段通常合并到一个Segment中int a = 20; // GLOBAL符号原创 2016-09-11 20:08:41 · 381 阅读 · 0 评论 -
c 语言 typedef 用法
#include typedef struct Student { int sid; int age;}* PST, ST;// PST 等价于struct Student *// ST 等价于 struct Studentint main(int argc, const char * argv[]) { ST st; PST ps= &st;原创 2016-03-09 22:43:45 · 315 阅读 · 0 评论 -
【数据结构与算法】(七) c 语言实现一种快速排序算法
//// main.c// QuickSort//// Created by lan on 16/3/19.// Copyright © 2016年 lan. All rights reserved.//#include void QuickSort(int *, int, int);int FindPos(int *, int, int);int main(in原创 2016-03-19 16:25:24 · 422 阅读 · 0 评论 -
【数据结构与算法】(四) c 语言静态队列的简单实现
//// main.c// testQueue//// Created by lan on 16/3/12.// Copyright © 2016年 lan. All rights reserved.///* 静态队列:用数组实现 静态队列通常必须是循环队列 因为:无论是出队还是入队,头指针和尾指针都必须只加不减 如果不是循环队列,原创 2016-03-12 22:42:20 · 709 阅读 · 0 评论 -
【数据结构与算法】(三) c 语言栈的简单实现
//// main.c// testStack//// Created by lan on 16/3/11.// Copyright © 2016年 lan. All rights reserved.//#include #include #include #include typedef struct Node { int data; struc原创 2016-03-12 16:08:44 · 560 阅读 · 0 评论 -
【数据结构与算法】(二) c 语言链表的简单操作
//// main.c// testLink//// Created by lan on 16/3/6.// Copyright © 2016年 lan. All rights reserved.//#include #include #include #include typedef struct Node { int date;原创 2016-03-09 23:06:53 · 496 阅读 · 0 评论 -
【数据结构与算法】(一) c 语言实现数组的简单操作
//// main.c// TestArray//// Created by lan on 16/2/28.// Copyright © 2016年 lan. All rights reserved.//#include #include #include #include struct Arr { int *pBase; // 存储的是数组第一个元素的原创 2016-03-09 23:01:53 · 681 阅读 · 0 评论