GithubHelp home page GithubHelp logo

tiancheng-luo / 21st-century-examples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from b-k/21st-century-examples

0.0 1.0 0.0 78 KB

Examples for _21st Century C_ by Ben Klemens

Home Page: http://tinyurl.com/c-for-moderns-2

Shell 1.05% C 89.95% Objective-C 0.40% Makefile 0.54% M4 0.34% CWeb 7.73%

21st-century-examples's Introduction

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

21st-century-examples's People

Contributors

b-k avatar benwaffle avatar bl4krat avatar fooofei avatar machste avatar viccuad avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.