• Stars
    star
    332
  • Rank 122,676 (Top 3 %)
  • Language
    C
  • Created over 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Examples for _21st Century C_ by 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.c > 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

More Repositories

1

py1040

A U.S. personal income tax calculator
Python
315
star
2

apophenia

A C library for statistical and scientific computing
C
196
star
3

1040.js

A visual implementation of individual U.S. taxes
JavaScript
37
star
4

mms

The Malcontent Management System
TeX
32
star
5

wearin

The more you play your music files, the more they wear in
C
6
star
6

Rapophenia

C
6
star
7

narratives-distributions

A table of concrete micro-level narratives known to generate closed-form statistical distributions.
TeX
5
star
8

cat_notes

My notes and flash cards for category theory
TeX
5
star
9

modeling_examples

Collected examples of modeling
C
5
star
10

dataclub

Like a book club, but with data.
Jupyter Notebook
3
star
11

tweets-are-not-news

Remove headlines from news sites with titles including words like "lambasts", "blasts", "jabs"
JavaScript
3
star
12

git-isclean

Q: Would I lose any work by deleting a local clone of a git repository? A: Run this script to find out.
3
star
13

unicode-falafel

A proposal to add a falafel emoji to the Unicode standard
TeX
2
star
14

tea-tutorial

A tutorial introduction to Tea, an R package for survey processing
TeX
2
star
15

luminosity

A paper on the using light visible at night from space and poverty
C
2
star
16

ml_for_econometricians

Slides and demo script for a talk for IMF econometricians on machine learning
TeX
2
star
17

cmh.py

Cochrane-Mantel-Hanenszel statistic calculator
Jupyter Notebook
1
star
18

small-world-motifs

Count subgraphs and generate random graphs, using a Lua library for storing graphs in a Berkeley DB.
C
1
star
19

ethical-principles-for-disruption

A discussion of ethical principles for developers and technologists
1
star