百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
2

21st-Century-Examples

> 编程语言
开源

《21 世纪 C》的示例,作者: Ben Klemens

360 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

《21 世纪 C》的示例,作者: Ben Klemens

21st-Century-Examples

Dear Reader,

Here are all of the examples from the second edition of 21st Century C by Ben Klemens [ http://tinyurl.com/c-for-moderns-2 ]. You'll notice that the captions for all of the examples in the text end in a filename in parens, like (string_utilities.c); that name is referring to the file here.

  • Each .c file has a note about how to compile it. Some involve a makefile, and some have a command or two to cut/paste onto your command line. dict_use.c includes an extensive script that runs autoconf on the system.

  • Everything is UTF-8. If you are using Windows and the encoding becomes relevant, try iconv -f UTF-8 -t UTF-16 unicode.16.c

  • I assume you have the requisite libraries in place, including the GSL and GLib. If installing via package manager, don't forget the -dev or -devel packages. One or two of the examples require Apophenia (available from http://apophenia.info), CWEB, or other requisites which should be obvious from the header, and you can't run the Autotools examples without having Autoconf, Automake, and Libtool installed.

  • All of the CFLAGS use the GCC's -std=gnu11 flag, requesting that GCC use the C11 standard. If you have an older copy of GCC that predates C11 support, you'll need to change every instance to -std=gnu99. There exist other compilers that don't understand this flag, and you'll need to delete it entirely.

Here's the GNU sed command to do the changes on every .c file in the current directory all at once:

#For a version of GCC that predates C11:
sed -i -e 's/-std=gnu11/-std=gnu99/g' *.c

#For Clang and icc, which don't need the -std=... flag at all:
sed -i -e 's/-std=gnu11//g' *.c
  • If you get linker errors about resolving the (common but not C-standard) function asprintf, use the version provided as an example in asprintf.c, and the function declaration in that file. Or use the libiberty library, which means adding the -liberty flag to your LDLIBS. For example, MSYS includes libiberty as part of its development package.

Have fun with them,

Ben Klemens July 2012

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言