C: A Humbling Language

Preview:

DESCRIPTION

OSDC 2007 opening keynote. Not sure it makes sense if you weren't there, but someone asked for slides.

Citation preview

OSDC 2007

A Humbling Language

Rusty Russell

Time Better Spent

● tcmalloc– http://goog-perftools.sourceforge.net/doc/tcmalloc.html

● tdb– ftp://ftp.samba.org/pub/unpacked/tdb

● lguest– http://lguest.ozlabs.org

A B C D E F GH I J K L MN O P Q R S TU V W X Y Z

B C D G L MN O P R S U V W Z

C L MN O S V W Z

C O S

C OO S

C S

C SS

C

C

C

C: A Historic Language

http://www.thorstenkoerner.de/uploads/thompson_ritchie.jpg

+=registerentry

foo.c

foo.c

preprocessor

foo.c

preprocessor

#define FOO 17

foo.c

preprocessor

#define FOO(x) (17*(x))

foo.c

preprocessor

#ifdef LINUX...#else...#endif

foo.c

preprocessor

#include "foo.h"

foo.c

preprocessor

#include "foo.h"

foo.h

foo.c

preprocessor

#include "foo.h"

foo.h#include <stdio.h>

foo.c

preprocessor

#include "foo.h"

foo.h#include <stdio.h>

stdio.h

foo.c

preprocessor

#include "foo.h"

foo.h#include <stdio.h>

stdio.h

# include <features.h># include <stddef.h># include <bits/types.h>#include <libio.h># include <stdarg.h>#include <bits/stdio_lim.h>#include <bits/sys_errlist.h># include <getopt.h># include <bits/stdio.h># include <bits/stdio2.h># include <bits/stdio-ldbl.h>

foo.c

preprocessor

foo.c

preprocessor

foo.i

foo.c

preprocessor

foo.i

foo.c

preprocessor

compiler

foo.c

preprocessor

compiler

foo.c

preprocessor

compiler

foo.s

foo.c

preprocessor

compiler

assembler

foo.c bar.c baz.c

preprocessor

compiler

assembler

foo.c bar.c baz.c

preprocessor

compiler

assembler

linker

foo.c bar.c baz.c

preprocessor

compiler

assembler

linker

foobarbaz

foo.c bar.c baz.c

preprocessor

compiler

assembler

linker

foobarbaz

make

foo.c bar.c baz.c

preprocessor

compiler

assembler

linker

foobarbaz

make

ccache

foo.c bar.c baz.c

preprocessor

compiler

assembler

linker

foobarbaz

make

ccachedistcc

foo.c bar.c baz.c

preprocessor

compiler

assembler

linker

foobarbaz

make

ccachedistcc

ccontrol

foo.c bar.c baz.c

preprocessor

compiler

assembler

linker

foobarbaz

make

ccachedistcc

ccontrol

gcc *.c

1988

entryvoidconst

volatileenum

function prototypes

1999

inline

foo.c bar.c baz.c

preprocessor

compiler

assembler

linker

foobarbaz

int foo(int x)...

foo.c bar.c baz.c

preprocessor

compiler

assembler

linker

foobarbaz

int foo(int x)...

foo.c bar.c baz.c

preprocessor

compiler

assembler

linker

foobarbaz

foo.h

foo.c bar.c baz.c

preprocessor

compiler

assembler

linker

foobarbaz

foo.hinline int foo(int x)...

WTF?

WTF?This isn't a scripting

language!

Images from Wikipedia

C

C C

C CC C

Control

Cycles

Core

Cache

“Sell Me a C!”

The Magic

The Magic

struct list_head{

struct list_head *next, *prev;};

struct list_head{

struct list_head *next, *prev;};

struct thing{

struct list_head elem;...

};

void *kmalloc(size_t size, gfp_t flags);

Just a little magic?

long f(struct foo *a, struct foo *b){

return b – a;}

Magic to get closer to the machine...

struct elems{

unsigned int num_elems;struct elem[0];

};

#define memcpy(t, f, n) \ (__builtin_constant_p(n) ? \ __constant_memcpy((t),(f),(n)) : \ __memcpy((t),(f),(n)))

Magic to strengthen language features...

Magic to strengthen language features...DANGER!

#define new(type) \((type *)malloc(sizeof(type))

#define min(x,y) ({ \typeof(x) _x = (x); \typeof(y) _y = (y); \(void) (&_x == &_y); \_x < _y ? _x : _y; })

_Bool

#include <stdbool.h>

#include <stdbool.h>

#define bool _Bool

#define begin {#define end }

talloc(context, type)

valgrind

C

Recommended