C语言精髓简练教程
代码:https://gitee.com/hsjjsh123/eclipse-c
我的C语言回顾(彻底理解C指针)
何胜金,2021-04-29
arr[数组]
close_test[闭包测试]
define_s[宏定义]
enum_s[枚举]
f_time[时间格式化]
format[一般格式化]
func_pointer[指针函数、函数指针]
op_file[文件操作]
pointer[指针、指针数组、数组指针]
primit_pointer[基本数据类型与指针转换]
printf_s[格式化打印]
ptread_use[基础多线程使用]
size_t_s[库函数定义size_t使用]
struct_s[结构体]
str[字符串]
struct_s[结构体]
thread_poll[线程池–linux信号量–linux系统下使用]
typedef_s[typedef]
union_s[联合]
str[字符串、字符]
main_entry.c程序入口函数
指针数组–>最终强调目标指针 int *p[5]
数组指针–>最终强调目标数组 int (*p)[5]
关于threadpool线程池 Run an example(只编译测试threadpool部分)
- 关于threadpool线程池,请使用linux编译。https://github.com/Pithikos/C-Thread-Pool:
The library is not precompiled so you have to compile it with your project. The thread pool
uses POSIX threads so if you compile with gcc on Linux you have to use the flag -pthread like this:
gcc main_entry.c ./thread_pool/example.c ./thread_pool/thpool.c -D THPOOL_DEBUG -pthread -o main_entry
- 执行
./main_entry
使用cmake&make编译项目(全项目编译)
- make默认centos7已经安装(验证如下)
[root@wpuj3zui5est1ifj-0002 ~]# make -v
GNU Make 3.82
Built for x86_64-redhat-linux-gnu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.[root@wpuj3zui5est1ifj-0002 ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
- 安装cmake
#下载Cmake
wget https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz
#解压Cmake
tar xvf cmake-3.6.2.tar.gz && cd cmake-3.6.2/
#编译安装cmake
./bootstrap
gmake
gmake install
#查看编译后的cmake版本
/usr/local/bin/cmake --version
#移除原来的cmake版本
yum remove cmake -y
#新建软连接
ln -s /usr/local/bin/cmake /usr/bin/
#终端查看版本
cmake --version
#出现版本表示成功!cmake编译完成
[root@wpuj3zui5est1ifj-0002 cmake-3.6.2]# cmake --version
cmake version 3.6.2CMake suite maintained and supported by Kitware (kitware.com/cmake).
- 编译
# 项目根目录执行
cmake CMakeLists.txt
# 项目根目录执行
make
- 运行
# 项目根目录执行
./eclipse_c
pointer[指针、指针数组、数组指针]
- 下面的指针部分截取展示,全部代码见仓库地址~
#include #ifndef __POINTER_S_H__#define __POINTER_S_H__//开始指针
//指针大小8字节
//(指针指向数组地址)、(数组里面全是指针)
//void *表示未知类型的指针
//①一般指针和②数组、③字符串指针:①简单,②③复杂,是一片区域extern void pointer_test();#endif
#include "pointer_s.h"void pointer_test(){//测试指针8字节int a = 100;char* s = "我是字符串";int arr[6] = {1,2,3,4,5,6};int arr2[6] = {10,20,30,40,50,60};printf("pointer sizeof : %d\n",sizeof a);printf("pointer sizeof : %d\n",sizeof s);printf("pointer sizeof : %d\n",sizeof arr);int *p = &a;int (*pa)[6] = &arr;printf("pointer sizeof : %d\n",sizeof p);printf("pointer sizeof : %d\n",sizeof pa);//(指针指向数组地址)//数组指针int (*arr_p)[6] = &arr;//(数组里面全是地址)//指针数组int *p_arr[2] = {arr,arr2};//单指针intint *pi = arr;一维数组的数组指针好特殊,*arr_p取到的仍旧是数组下标0的地址/printf("(指针指向数组地址)取arr第二个,%d,%d,%d\n",(*arr_p)[1],(*arr_p)[1],*(*arr_p+1));printf("(数组里面全是指针)取arr2第二个,%d,%d,%d,%d\n",(*(p_arr+1))[1],p_arr[1][1],*(p_arr[1]+1),*((*(p_arr+1))+1));printf("(单指针指向数组地址)取arr第二个,%d\n",*(pi+1));//void *表示未知类型的指针//此时不知道数据类型占用内存字节大小,使用时候强转具体的指针类型void *v = &a;printf("void pointer:%d\n",*(int*)v);void *va = arr2;//等同于:&arr2[0]//printf("void pointer 取arr2第二个,%d,%d\n",*((*(int(*)[])va)+1),(*(int(*)[])va)[1]);int h = 88;char cs = 'A';int al[2] = {18,28};int *hp = &h;char *csp = &cs;int (*alp)[] = &al;//一般指针printf("直接命中值:%d\n",*hp);printf("直接命中值:%c\n",*csp);//数组、字符串指针printf("间接命中值:%d,%d\n",(*alp)[0],*(*alp+1));
}
#include
#include "./pointer/pointer_s.h"int main() {//指针pointer_test();return 0;
}

gitee:https://gitee.com/hsjjsh123/eclipse-c
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
