0% found this document useful (0 votes)
32 views52 pages

Beej S Guide To C Programming Brian Beej Jorgensen Hall PDF Download

Beej's Guide to C Programming by Brian Beej Jorgensen Hall is a comprehensive resource for learning C programming, covering topics from basic syntax to advanced concepts like pointers and arrays. The document includes sections on compiling code, variable types, flow control, and functions, making it suitable for beginners and experienced programmers alike. The latest version was updated in March 2023 and is available for download.

Uploaded by

zakiulduban
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views52 pages

Beej S Guide To C Programming Brian Beej Jorgensen Hall PDF Download

Beej's Guide to C Programming by Brian Beej Jorgensen Hall is a comprehensive resource for learning C programming, covering topics from basic syntax to advanced concepts like pointers and arrays. The document includes sections on compiling code, variable types, flow control, and functions, making it suitable for beginners and experienced programmers alike. The latest version was updated in March 2023 and is available for download.

Uploaded by

zakiulduban
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Beej s Guide to C Programming Brian Beej

Jorgensen Hall pdf download

https://ebookmeta.com/product/beej-s-guide-to-c-programming-
brian-beej-jorgensen-hall-3/

Download more ebook from https://ebookmeta.com


Beej’s Guide to C Programming

Brian “Beej Jorgensen” Hall

v0.9.13, Copyright © March 29, 2023


Contents

1 Foreword 1
1.1 Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 How to Read This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Platform and Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Official Homepage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.5 Email Policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.6 Mirroring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.7 Note for Translators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.8 Copyright and Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.9 Dedication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 Hello, World! 5
2.1 What to Expect from C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Hello, World! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Compilation Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.4 Building with gcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.5 Building with clang . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.6 Building from IDEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.7 C Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

3 Variables and Statements 10


3.1 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.1.1 Variable Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.1.2 Variable Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.1.3 Boolean Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2 Operators and Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2.1 Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2.2 Ternary Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2.3 Pre-and-Post Increment-and-Decrement . . . . . . . . . . . . . . . . . . . . . 14
3.2.4 The Comma Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2.5 Conditional Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2.6 Boolean Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2.7 The sizeof Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.3 Flow Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.3.1 The if-else statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3.2 The while statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.3.3 The do-while statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3.4 The for statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.3.5 The switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

4 Functions 23
4.1 Passing by Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.2 Function Prototypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.3 Empty Parameter Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

5 Pointers—Cower In Fear! 27
5.1 Memory and Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
5.2 Pointer Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

i
CONTENTS ii

5.3 Dereferencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.4 Passing Pointers as Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.5 The NULL Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.6 A Note on Declaring Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.7 sizeof and Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

6 Arrays 34
6.1 Easy Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
6.2 Getting the Length of an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
6.3 Array Initializers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
6.4 Out of Bounds! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.5 Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.6 Arrays and Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.6.1 Getting a Pointer to an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.6.2 Passing Single Dimensional Arrays to Functions . . . . . . . . . . . . . . . . . 39
6.6.3 Changing Arrays in Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 40
6.6.4 Passing Multidimensional Arrays to Functions . . . . . . . . . . . . . . . . . . 41

7 Strings 42
7.1 String Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7.2 String Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7.3 String Variables as Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7.4 String Initializers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
7.5 Getting String Length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
7.6 String Termination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
7.7 Copying a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

8 Structs 47
8.1 Declaring a Struct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
8.2 Struct Initializers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
8.3 Passing Structs to Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
8.4 The Arrow Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
8.5 Copying and Returning structs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
8.6 Comparing structs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

9 File Input/Output 51
9.1 The FILE* Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
9.2 Reading Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
9.3 End of File: EOF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
9.3.1 Reading a Line at a Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
9.4 Formatted Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
9.5 Writing Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
9.6 Binary File I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
9.6.1 struct and Number Caveats . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

10 typedef: Making New Types 58


10.1 typedef in Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
10.1.1 Scoping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
10.2 typedef in Practice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
10.2.1 typedef and structs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
10.2.2 typedef and Other Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
10.2.3 typedef and Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
10.2.4 typedef and Capitalization . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
10.3 Arrays and typedef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

11 Pointers II: Arithmetic 62


11.1 Pointer Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
11.1.1 Adding to Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
11.1.2 Changing Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
CONTENTS iii

11.1.3 Subtracting Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64


11.2 Array/Pointer Equivalence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
11.2.1 Array/Pointer Equivalence in Function Calls . . . . . . . . . . . . . . . . . . . 65
11.3 void Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

12 Manual Memory Allocation 70


12.1 Allocating and Deallocating, malloc() and free() . . . . . . . . . . . . . . . . . . 70
12.2 Error Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
12.3 Allocating Space for an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
12.4 An Alternative: calloc() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
12.5 Changing Allocated Size with realloc() . . . . . . . . . . . . . . . . . . . . . . . 73
12.5.1 Reading in Lines of Arbitrary Length . . . . . . . . . . . . . . . . . . . . . . 74
12.5.2 realloc() with NULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
12.6 Aligned Allocations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

13 Scope 78
13.1 Block Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
13.1.1 Where To Define Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
13.1.2 Variable Hiding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
13.2 File Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
13.3 for-loop Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
13.4 A Note on Function Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

14 Types II: Way More Types! 81


14.1 Signed and Unsigned Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
14.2 Character Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
14.3 More Integer Types: short, long, long long . . . . . . . . . . . . . . . . . . . . . 83
14.4 More Float: double and long double . . . . . . . . . . . . . . . . . . . . . . . . 85
14.4.1 How Many Decimal Digits? . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
14.4.2 Converting to Decimal and Back . . . . . . . . . . . . . . . . . . . . . . . . . 87
14.5 Constant Numeric Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
14.5.1 Hexadecimal and Octal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
14.5.2 Integer Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
14.5.3 Floating Point Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

15 Types III: Conversions 92


15.1 String Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
15.1.1 Numeric Value to String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
15.1.2 String to Numeric Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
15.2 char Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
15.3 Numeric Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
15.3.1 Boolean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
15.3.2 Integer to Integer Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . 96
15.3.3 Integer and Floating Point Conversions . . . . . . . . . . . . . . . . . . . . . 96
15.4 Implicit Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
15.4.1 The Integer Promotions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
15.4.2 The Usual Arithmetic Conversions . . . . . . . . . . . . . . . . . . . . . . . . 97
15.4.3 void* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
15.5 Explicit Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
15.5.1 Casting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98

16 Types IV: Qualifiers and Specifiers 100


16.1 Type Qualifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
16.1.1 const . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
16.1.2 restrict . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
16.1.3 volatile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
16.1.4 _Atomic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
16.2 Storage-Class Specifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
16.2.1 auto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
CONTENTS iv

16.2.2 static . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104


16.2.3 extern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
16.2.4 register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
16.2.5 _Thread_local . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

17 Multifile Projects 107


17.1 Includes and Function Prototypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
17.2 Dealing with Repeated Includes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
17.3 static and extern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
17.4 Compiling with Object Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110

18 The Outside Environment 111


18.1 Command Line Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
18.1.1 The Last argv is NULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
18.1.2 The Alternate: char **argv . . . . . . . . . . . . . . . . . . . . . . . . . . 113
18.1.3 Fun Facts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
18.2 Exit Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
18.2.1 Other Exit Status Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
18.3 Environment Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
18.3.1 Setting Environment Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 117
18.3.2 Unix-like Alternative Environment Variables . . . . . . . . . . . . . . . . . . . 117

19 The C Preprocessor 119


19.1 #include . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
19.2 Simple Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
19.3 Conditional Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
19.3.1 If Defined, #ifdef and #endif . . . . . . . . . . . . . . . . . . . . . . . . . 120
19.3.2 If Not Defined, #ifndef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
19.3.3 #else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
19.3.4 General Conditional: #if, #elif . . . . . . . . . . . . . . . . . . . . . . . . 122
19.3.5 Losing a Macro: #undef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
19.4 Built-in Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
19.4.1 Mandatory Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
19.4.2 Optional Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
19.5 Macros with Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
19.5.1 Macros with One Argument . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
19.5.2 Macros with More than One Argument . . . . . . . . . . . . . . . . . . . . . . 127
19.5.3 Macros with Variable Arguments . . . . . . . . . . . . . . . . . . . . . . . . . 128
19.5.4 Stringification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
19.5.5 Concatenation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
19.6 Multiline Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
19.7 Example: An Assert Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
19.8 The #error Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
19.9 The #pragma Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
19.9.1 Non-Standard Pragmas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
19.9.2 Standard Pragmas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
19.9.3 _Pragma Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
19.10 The #line Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
19.11 The Null Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

20 structs II: More Fun with structs 134


20.1 Initializers of Nested structs and Arrays . . . . . . . . . . . . . . . . . . . . . . . 134
20.2 Anonymous structs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
20.3 Self-Referential structs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
20.4 Flexible Array Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
20.5 Padding Bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
20.6 offsetof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
20.7 Fake OOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
20.8 Bit-Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
CONTENTS v

20.8.1 Non-Adjacent Bit-Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142


20.8.2 Signed or Unsigned ints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
20.8.3 Unnamed Bit-Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
20.8.4 Zero-Width Unnamed Bit-Fields . . . . . . . . . . . . . . . . . . . . . . . . . 143
20.9 Unions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
20.9.1 Unions and Type Punning . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
20.9.2 Pointers to unions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
20.9.3 Common Initial Sequences in Unions . . . . . . . . . . . . . . . . . . . . . . 145
20.10 Unions and Unnamed Structs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
20.11 Passing and Returning structs and unions . . . . . . . . . . . . . . . . . . . . . . 148

21 Characters and Strings II 150


21.1 Escape Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
21.1.1 Frequently-used Escapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
21.1.2 Rarely-used Escapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
21.1.3 Numeric Escapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

22 Enumerated Types: enum 154


22.1 Behavior of enum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
22.1.1 Numbering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
22.1.2 Trailing Commas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
22.1.3 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
22.1.4 Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
22.2 Your enum is a Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

23 Pointers III: Pointers to Pointers and More 157


23.1 Pointers to Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
23.1.1 Pointer Pointers and const . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
23.2 Multibyte Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
23.3 The NULL Pointer and Zero . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
23.4 Pointers as Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
23.5 Casting Pointers to other Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
23.6 Pointer Differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
23.7 Pointers to Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

24 Bitwise Operations 167


24.1 Bitwise AND, OR, XOR, and NOT . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
24.2 Bitwise Shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

25 Variadic Functions 169


25.1 Ellipses in Function Signatures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
25.2 Getting the Extra Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
25.3 va_list Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
25.4 Library Functions That Use va_lists . . . . . . . . . . . . . . . . . . . . . . . . . 171

26 Locale and Internationalization 173


26.1 Setting the Localization, Quick and Dirty . . . . . . . . . . . . . . . . . . . . . . . . 173
26.2 Getting the Monetary Locale Settings . . . . . . . . . . . . . . . . . . . . . . . . . . 174
26.2.1 Monetary Digit Grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
26.2.2 Separators and Sign Position . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
26.2.3 Example Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
26.3 Localization Specifics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176

27 Unicode, Wide Characters, and All That 178


27.1 What is Unicode? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
27.2 Code Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
27.3 Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
27.4 Source and Execution Character Sets . . . . . . . . . . . . . . . . . . . . . . . . . . 180
27.5 Unicode in C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
CONTENTS vi

27.6 A Quick Note on UTF-8 Before We Swerve into the Weeds . . . . . . . . . . . . . . 181
27.7 Different Character Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
27.7.1 Multibyte Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
27.7.2 Wide Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
27.8 Using Wide Characters and wchar_t . . . . . . . . . . . . . . . . . . . . . . . . . . 183
27.8.1 Multibyte to wchar_t Conversions . . . . . . . . . . . . . . . . . . . . . . . . 184
27.9 Wide Character Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
27.9.1 wint_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
27.9.2 I/O Stream Orientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
27.9.3 I/O Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
27.9.4 Type Conversion Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
27.9.5 String and Memory Copying Functions . . . . . . . . . . . . . . . . . . . . . 186
27.9.6 String and Memory Comparing Functions . . . . . . . . . . . . . . . . . . . . 186
27.9.7 String Searching Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
27.9.8 Length/Miscellaneous Functions . . . . . . . . . . . . . . . . . . . . . . . . . 187
27.9.9 Character Classification Functions . . . . . . . . . . . . . . . . . . . . . . . . 187
27.10 Parse State, Restartable Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
27.11 Unicode Encodings and C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
27.11.1 UTF-8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
27.11.2 UTF-16, UTF-32, char16_t, and char32_t . . . . . . . . . . . . . . . . . . . 190
27.11.3 Multibyte Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
27.11.4 Third-Party Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191

28 Exiting a Program 192


28.1 Normal Exits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
28.1.1 Returning From main() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
28.1.2 exit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
28.1.3 Setting Up Exit Handlers with atexit() . . . . . . . . . . . . . . . . . . . . 193
28.2 Quicker Exits with quick_exit() . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
28.3 Nuke it from Orbit: _Exit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
28.4 Exiting Sometimes: assert() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
28.5 Abnormal Exit: abort() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194

29 Signal Handling 196


29.1 What Are Signals? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
29.2 Handling Signals with signal() . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
29.3 Writing Signal Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
29.4 What Can We Actually Do? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
29.5 Friends Don’t Let Friends signal() . . . . . . . . . . . . . . . . . . . . . . . . . . 200

30 Variable-Length Arrays (VLAs) 201


30.1 The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
30.2 sizeof and VLAs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
30.3 Multidimensional VLAs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
30.4 Passing One-Dimensional VLAs to Functions . . . . . . . . . . . . . . . . . . . . . 203
30.5 Passing Multi-Dimensional VLAs to Functions . . . . . . . . . . . . . . . . . . . . . 204
30.5.1 Partial Multidimensional VLAs . . . . . . . . . . . . . . . . . . . . . . . . . 204
30.6 Compatibility with Regular Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
30.7 typedef and VLAs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
30.8 Jumping Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
30.9 General Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206

31 goto 207
31.1 A Simple Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
31.2 Labeled continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
31.3 Bailing Out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
31.4 Labeled break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
31.5 Multi-level Cleanup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
31.6 Tail Call Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
CONTENTS vii

31.7 Restarting Interrupted System Calls . . . . . . . . . . . . . . . . . . . . . . . . . . 212


31.8 goto and Thread Preemption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
31.9 goto and Variable Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
31.10 goto and Variable-Length Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214

32 Types Part V: Compound Literals and Generic Selections 215


32.1 Compound Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
32.1.1 Passing Unnamed Objects to Functions . . . . . . . . . . . . . . . . . . . . . 215
32.1.2 Unnamed structs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
32.1.3 Pointers to Unnamed Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
32.1.4 Unnamed Objects and Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
32.1.5 Silly Unnamed Object Example . . . . . . . . . . . . . . . . . . . . . . . . . 218
32.2 Generic Selections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218

33 Arrays Part II 221


33.1 Type Qualifiers for Arrays in Parameter Lists . . . . . . . . . . . . . . . . . . . . . . 221
33.2 static for Arrays in Parameter Lists . . . . . . . . . . . . . . . . . . . . . . . . . . 221
33.3 Equivalent Initializers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222

34 Long Jumps with setjmp, longjmp 225


34.1 Using setjmp and longjmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
34.2 Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
34.2.1 The Values of Local Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 226
34.2.2 How Much State is Saved? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
34.2.3 You Can’t Name Anything setjmp . . . . . . . . . . . . . . . . . . . . . . . . 227
34.2.4 You Can’t setjmp() in a Larger Expression . . . . . . . . . . . . . . . . . . . 227
34.2.5 When Can’t You longjmp()? . . . . . . . . . . . . . . . . . . . . . . . . . . 228
34.2.6 You Can’t Pass 0 to longjmp() . . . . . . . . . . . . . . . . . . . . . . . . . 228
34.2.7 longjmp() and Variable Length Arrays . . . . . . . . . . . . . . . . . . . . . 228

35 Incomplete Types 229


35.1 Use Case: Self-Referential Structures . . . . . . . . . . . . . . . . . . . . . . . . . . 229
35.2 Incomplete Type Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
35.3 Other Incomplete Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
35.4 Use Case: Arrays in Header Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
35.5 Completing Incomplete Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231

36 Complex Numbers 233


36.1 Complex Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
36.2 Assigning Complex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
36.3 Constructing, Deconstructing, and Printing . . . . . . . . . . . . . . . . . . . . . . . 234
36.4 Complex Arithmetic and Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . 235
36.5 Complex Math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
36.5.1 Trigonometry Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
36.5.2 Exponential and Logarithmic Functions . . . . . . . . . . . . . . . . . . . . . 237
36.5.3 Power and Absolute Value Functions . . . . . . . . . . . . . . . . . . . . . . . 237
36.5.4 Manipulation Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237

37 Fixed Width Integer Types 238


37.1 The Bit-Sized Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
37.2 Maximum Integer Size Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
37.3 Using Fixed Size Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
37.4 Limits of Fixed Size Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
37.5 Format Specifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240

38 Date and Time Functionality 242


38.1 Quick Terminology and Information . . . . . . . . . . . . . . . . . . . . . . . . . . 242
38.2 Date Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
38.3 Initialization and Conversion Between Types . . . . . . . . . . . . . . . . . . . . . . 243
CONTENTS viii

38.3.1 Converting time_t to struct tm . . . . . . . . . . . . . . . . . . . . . . . . 243


38.3.2 Converting struct tm to time_t . . . . . . . . . . . . . . . . . . . . . . . . 244
38.4 Formatted Date Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
38.5 More Resolution with timespec_get() . . . . . . . . . . . . . . . . . . . . . . . . 246
38.6 Differences Between Times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246

39 Multithreading 248
39.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
39.2 Things You Can Do . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
39.3 Data Races and the Standard Library . . . . . . . . . . . . . . . . . . . . . . . . . . 249
39.4 Creating and Waiting for Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
39.5 Detaching Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
39.6 Thread Local Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
39.6.1 _Thread_local Storage-Class . . . . . . . . . . . . . . . . . . . . . . . . . 255
39.6.2 Another Option: Thread-Specific Storage . . . . . . . . . . . . . . . . . . . . 256
39.7 Mutexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
39.7.1 Different Mutex Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
39.8 Condition Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
39.8.1 Timed Condition Wait . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
39.8.2 Broadcast: Wake Up All Waiting Threads . . . . . . . . . . . . . . . . . . . . 265
39.9 Running a Function One Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265

40 Atomics 266
40.1 Testing for Atomic Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
40.2 Atomic Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
40.3 Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
40.4 Acquire and Release . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
40.5 Sequential Consistency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
40.6 Atomic Assignments and Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
40.7 Library Functions that Automatically Synchronize . . . . . . . . . . . . . . . . . . . 272
40.8 Atomic Type Specifier, Qualifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
40.9 Lock-Free Atomic Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
40.9.1 Signal Handlers and Lock-Free Atomics . . . . . . . . . . . . . . . . . . . . . 275
40.10 Atomic Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
40.11 Atomic structs and unions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
40.12 Atomic Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
40.13 Memory Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
40.13.1 Sequential Consistency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
40.13.2 Acquire . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
40.13.3 Release . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
40.13.4 Consume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
40.13.5 Acquire/Release . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
40.13.6 Relaxed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
40.14 Fences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
40.15 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279

41 Function Specifiers, Alignment Specifiers/Operators 281


41.1 Function Specifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
41.1.1 inline for Speed—Maybe . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
41.1.2 noreturn and _Noreturn . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
41.2 Alignment Specifiers and Operators . . . . . . . . . . . . . . . . . . . . . . . . . . 284
41.2.1 alignas and _Alignas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
41.2.2 alignof and _Alignof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Chapter 1

Foreword

C is not a big language, and it is not well served by a big book.


–Brian W. Kernighan, Dennis M. Ritchie
No point in wasting words here, folks, let’s jump straight into the C code:
E((ck?main((z?(stat(M,&t)?P+=a+'{'?0:3:
execv(M,k),a=G,i=P,y=G&255,
sprintf(Q,y/'@'-3?A(*L(V(%d+%d)+%d,0)

And they lived happily ever after. The End.


What’s this? You say something’s still not clear about this whole C programming language thing?
Well, to be quite honest, I’m not even sure what the above code does. It’s a snippet from one of the entries
in the 2001 International Obfuscated C Code Contest1 , a wonderful competition wherein the entrants
attempt to write the most unreadable C code possible, with often surprising results.
The bad news is that if you’re a beginner in this whole thing, all C code you see probably looks obfuscated!
The good news is, it’s not going to be that way for long.
What we’ll try to do over the course of this guide is lead you from complete and utter sheer lost confusion
on to the sort of enlightened bliss that can only be obtained through pure C programming. Right on.
In the old days, C was a simpler language. A good number of the features contained in this book and a lot
of the features in the Library Reference volume didn’t exist when K&R wrote the famous second edition
of their book in 1988. Nevertheless, the language remains small at its core, and I hope I’ve presented it
here in a way that starts with that simple core and builds outward.
And that’s my excuse for writing such a hilariously large book for such a small, concise language.

1.1 Audience
This guide assumes that you’ve already got some programming knowledge under your belt from another
language, such as Python2 , JavaScript3 , Java4 , Rust5 , Go6 , Swift7 , etc. (Objective-C8 devs will have a
particularly easy time of it!)
We’re going to assume you know what variables are, what loops do, how functions work, and so on.
1
https://www.ioccc.org/
2
https://en.wikipedia.org/wiki/Python_(programming_language)
3
https://en.wikipedia.org/wiki/JavaScript
4
https://en.wikipedia.org/wiki/Java_(programming_language)
5
https://en.wikipedia.org/wiki/Rust_(programming_language)
6
https://en.wikipedia.org/wiki/Go_(programming_language)
7
https://en.wikipedia.org/wiki/Swift_(programming_language)
8
https://en.wikipedia.org/wiki/Objective-C

1
Chapter 1. Foreword 2

If that’s not you for whatever reason the best I can hope to provide is some honest entertainment for your
reading pleasure. The only thing I can reasonably promise is that this guide won’t end on a cliffhanger…
or will it?

1.2 How to Read This Book


The guide is in two volumes, and this is the first: the tutorial volume!
The second volume is the library reference9 , and it’s far more reference than tutorial.
If you’re new, go through the tutorial part in order, generally. The higher you get in chapters, the less
important it is to go in order.
And no matter your skill level, the reference part is there with complete examples of the standard library
function calls to help refresh your memory whenever needed. Good for reading over a bowl of cereal or
other time.
Finally, glancing at the index (if you’re reading the print version), the reference section entries are itali-
cized.

1.3 Platform and Compiler


I’ll try to stick to Plain Ol’-Fashioned ISO-standard C10 . Well, for the most part. Here and there I might
go crazy and start talking about POSIX11 or something, but we’ll see.
Unix users (e.g. Linux, BSD, etc.) try running cc or gcc from the command line–you might already have
a compiler installed. If you don’t, search your distribution for installing gcc or clang.
Windows users should check out Visual Studio Community12 . Or, if you’re looking for a more Unix-like
experience (recommended!), install WSL13 and gcc.
Mac users will want to install XCode14 , and in particular the command line tools.
There are a lot of compilers out there, and virtually all of them will work for this book. And a C++ compiler
will compile a lot of (but not all!) C code. Best use a proper C compiler if you can.

1.4 Official Homepage


This official location of this document is https://beej.us/guide/bgc/15 . Maybe this’ll change in the future,
but it’s more likely that all the other guides are migrated off Chico State computers.

1.5 Email Policy


I’m generally available to help out with email questions so feel free to write in, but I can’t guarantee a
response. I lead a pretty busy life and there are times when I just can’t answer a question you have. When
that’s the case, I usually just delete the message. It’s nothing personal; I just won’t ever have the time to
give the detailed answer you require.
As a rule, the more complex the question, the less likely I am to respond. If you can narrow down your
question before mailing it and be sure to include any pertinent information (like platform, compiler, error
messages you’re getting, and anything else you think might help me troubleshoot), you’re much more
likely to get a response.
9
https://beej.us/guide/bgclr/
10
https://en.wikipedia.org/wiki/ANSI_C
11
https://en.wikipedia.org/wiki/POSIX
12
https://visualstudio.microsoft.com/vs/community/
13
https://docs.microsoft.com/en-us/windows/wsl/install-win10
14
https://developer.apple.com/xcode/
15
https://beej.us/guide/bgc/
Chapter 1. Foreword 3

If you don’t get a response, hack on it some more, try to find the answer, and if it’s still elusive, then write
me again with the information you’ve found and hopefully it will be enough for me to help out.
Now that I’ve badgered you about how to write and not write me, I’d just like to let you know that I fully
appreciate all the praise the guide has received over the years. It’s a real morale boost, and it gladdens me
to hear that it is being used for good! :-) Thank you!

1.6 Mirroring
You are more than welcome to mirror this site, whether publicly or privately. If you publicly mirror the
site and want me to link to it from the main page, drop me a line at [email protected].

1.7 Note for Translators


If you want to translate the guide into another language, write me at [email protected] and I’ll link to your
translation from the main page. Feel free to add your name and contact info to the translation.
Please note the license restrictions in the Copyright and Distribution section, below.

1.8 Copyright and Distribution


Beej’s Guide to C is Copyright © 2021 Brian “Beej Jorgensen” Hall.
With specific exceptions for source code and translations, below, this work is licensed under the Cre-
ative Commons Attribution-Noncommercial-No Derivative Works 3.0 License. To view a copy of this
license, visit https://creativecommons.org/licenses/by-nc-nd/3.0/ or send a letter to Creative
Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
One specific exception to the “No Derivative Works” portion of the license is as follows: this guide may
be freely translated into any language, provided the translation is accurate, and the guide is reprinted in
its entirety. The same license restrictions apply to the translation as to the original guide. The translation
may also include the name and contact information for the translator.
The C source code presented in this document is hereby granted to the public domain, and is completely
free of any license restriction.
Educators are freely encouraged to recommend or supply copies of this guide to their students.
Contact [email protected] for more information.

1.9 Dedication
The hardest things about writing these guides are:
• Learning the material in enough detail to be able to explain it
• Figuring out the best way to explain it clearly, a seemingly-endless iterative process
• Putting myself out there as a so-called authority, when really I’m just a regular human trying to
make sense of it all, just like everyone else
• Keeping at it when so many other things draw my attention
A lot of people have helped me through this process, and I want to acknowledge those who have made
this book possible.
• Everyone on the Internet who decided to help share their knowledge in one form or another. The
free sharing of instructive information is what makes the Internet the great place that it is.
• The volunteers at cppreference.com16 who provide the bridge that leads from the spec to the real
world.
16
https://en.cppreference.com/
Chapter 1. Foreword 4

• The helpful and knowledgeable folks on comp.lang.c17 and r/C_Programming18 who got me through
the tougher parts of the language.
• Everyone who submitted corrections and pull-requests on everything from misleading instructions
to typos.
Thank you! ♥

17
https://groups.google.com/g/comp.lang.c
18
https://www.reddit.com/r/C_Programming/
Chapter 2

Hello, World!

2.1 What to Expect from C


“Where do these stairs go?”
“They go up.”
—Ray Stantz and Peter Venkman, Ghostbusters
C is a low-level language.
It didn’t use to be. Back in the day when people carved punch cards out of granite, C was an incredible
way to be free of the drudgery of lower-level languages like assembly1 .
But now in these modern times, current-generation languages offer all kinds of features that didn’t exist
in 1972 when C was invented. This means C is a pretty basic language with not a lot of features. It can
do anything, but it can make you work for it.
So why would we even use it today?
• As a learning tool: not only is C a venerable piece of computing history, but it is connected to the
bare metal2 in a way that present-day languages are not. When you learn C, you learn about how
software interfaces with computer memory at a low level. There are no seatbelts. You’ll write
software that crashes, I assure you. And that’s all part of the fun!
• As a useful tool: C still is used for certain applications, such as building operating systems3 or in
embedded systems4 . (Though the Rust5 programming language is eyeing both these fields!)
If you’re familiar with another language, a lot of things about C are easy. C inspired many other languages,
and you’ll see bits of it in Go, Rust, Swift, Python, JavaScript, Java, and all kinds of other languages.
Those parts will be familiar.
The one thing about C that hangs people up is pointers. Virtually everything else is familiar, but pointers
are the weird one. The concept behind pointers is likely one you already know, but C forces you to be
explicit about it, using operators you’ve likely never seen before.
It’s especially insidious because once you grok6 pointers, they’re suddenly easy. But up until that moment,
they’re slippery eels.
Everything else in C is just memorizing another way (or sometimes the same way!) of doing something
you’ve done already. Pointers are the weird bit. And, arguably, even pointers are variations on a theme
you’re probably familiar with.
1
https://en.wikipedia.org/wiki/Assembly_language
2
https://en.wikipedia.org/wiki/Bare_machine
3
https://en.wikipedia.org/wiki/Operating_system
4
https://en.wikipedia.org/wiki/Embedded_system
5
https://en.wikipedia.org/wiki/Rust_(programming_language)
6
https://en.wikipedia.org/wiki/Grok

5
Chapter 2. Hello, World! 6

So get ready for a rollicking adventure as close to the core of the computer as you can get without assembly,
in the most influential computer language of all time7 . Hang on!

2.2 Hello, World!


This is the canonical example of a C program. Everyone uses it. (Note that the numbers to the left are for
reader reference only, and are not part of the source code.)
1 /* Hello world program */
2

3 #include <stdio.h>
4

5 int main(void)
6 {
7 printf("Hello, World!\n"); // Actually do the work here
8 }

We’re going to don our long-sleeved heavy-duty rubber gloves, grab a scalpel, and rip into this thing to
see what makes it tick. So, scrub up, because here we go. Cutting very gently…
Let’s get the easy thing out of the way: anything between the digraphs /* and */ is a comment and will
be completely ignored by the compiler. Same goes for anything on a line after a //. This allows you
to leave messages to yourself and others, so that when you come back and read your code in the distant
future, you’ll know what the heck it was you were trying to do. Believe me, you will forget; it happens.
Now, what is this #include? GROSS! Well, it tells the C Preprocessor to pull the contents of another file
and insert it into the code right there.
Wait—what’s a C Preprocessor? Good question. There are two stages8 to compilation: the preprocessor
and the compiler. Anything that starts with pound sign, or “octothorpe”, (#) is something the preprocessor
operates on before the compiler even gets started. Common preprocessor directives, as they’re called, are
#include and #define. More on that later.

Before we go on, why would I even begin to bother pointing out that a pound sign is called an octothorpe?
The answer is simple: I think the word octothorpe is so excellently funny, I have to gratuitously spread its
name around whenever I get the opportunity. Octothorpe. Octothorpe, octothorpe, octothorpe.
So anyway. After the C preprocessor has finished preprocessing everything, the results are ready for
the compiler to take them and produce assembly code9 , machine code10 , or whatever it’s about to do.
Machine code is the “language” the CPU understands, and it can understand it very rapidly. This is one
of the reasons C programs tend to be quick.
Don’t worry about the technical details of compilation for now; just know that your source runs through
the preprocessor, then the output of that runs through the compiler, then that produces an executable for
you to run.
What about the rest of the line? What’s <stdio.h>? That is what is known as a header file. It’s the
dot-h at the end that gives it away. In fact it’s the “Standard I/O” (stdio) header file that you will grow
to know and love. It gives us access to a bunch of I/O functionality11 . For our demo program, we’re
outputting the string “Hello, World!”, so we in particular need access to the printf() function to do
this. The <stdio.h> file gives us this access. Basically, if we tried to use printf() without #include
<stdio.h>, the compiler would have complained to us about it.

How did I know I needed to #include <stdio.h> for printf()? Answer: it’s in the documentation.
If you’re on a Unix system, man 3 printf and it’ll tell you right at the top of the man page what header
files are required. Or see the reference section in this book. :-)
7
I know someone will fight me on that, but it’s gotta be at least in the top three, right?
8
Well, technically there are more than two, but hey, let’s pretend there are two—ignorance is bliss, right?
9
https://en.wikipedia.org/wiki/Assembly_language
10
https://en.wikipedia.org/wiki/Machine_code
11
Technically, it contains preprocessor directives and function prototypes (more on that later) for common input and output needs.
Exploring the Variety of Random
Documents with Different Content
voluntarily under no other sanction than the desire to retain their
positions as officials.
The organization of the Security Police and SD also included
three special units which must be dealt with separately. The first of
these was the Frontier Police or Grenzpolizei which came under the
control of the Gestapo in 1937. Their duties consisted in the control
of passage over the borders of Germany. They arrested persons who
crossed illegally. It is also clear from the evidence presented that
they received directives from the Gestapo to transfer foreign workers
whom they apprehended to concentration camps. They could also
request the local office of the Gestapo for permission to commit
persons arrested to concentration camps. The Tribunal is of the
opinion that the Frontier Police must be included in the charge of
criminality against the Gestapo.
The border and customs protection or Zollgrenzschutz became
part of the Gestapo in the summer of 1944. The functions of this
organization were similar to the Frontier Police in enforcing border
regulations with particular respect to the prevention of smuggling. It
does not appear, however, that their transfer was complete but that
about half of their personnel of 54,000 remained under the Reich
Finance Administration or the Order Police. A few days before the
end of the war the whole organization was transferred back to the
Reich Finance Administration. The transfer of the organization to the
Gestapo was so late and it participated so little in the over-all
activities of the organization that the Tribunal does not feel that it
should be dealt with in considering the criminality of the Gestapo.
The third organization was the so-called Secret Field Police which
was originally under the Army but which in 1942 was transferred by
military order to the Security Police. The Secret Field police was
concerned with security matters within the Army in occupied
territory, and also with the prevention of attacks by civilians on
military installations or units, and committed War Crimes and Crimes
against Humanity on a wide scale. It has not been proved, however,
that it was a part of the Gestapo and the Tribunal does not consider
it as coming within the charge of criminality contained in the
Indictment, except such members as may have been transferred to
Amt IV of the RSHA or were members of organizations declared
criminal by this Judgment.
Criminal Activity: Originally, one of the primary functions of the
Gestapo was the prevention of any political opposition to the Nazi
regime, a function which it performed with the assistance of the SD.
The principal weapon used in performing this function was the
concentration camp. The Gestapo did not have administrative control
over the concentration camps, but, acting through the RSHA, was
responsible for the detention of political prisoners in those camps.
Gestapo officials were usually responsible for the interrogation of
political prisoners at the camps.
The Gestapo and the SD also dealt with charges of treason and
with questions relating to the press, the churches and the Jews. As
the Nazi program of anti-Semitic persecution increased in intensity
the role played by these groups became increasingly important. In
the early morning of 10 November 1938, Heydrich sent a telegram
to all offices of the Gestapo and SD giving instructions for the
organization of the pogroms of that date and instructing them to
arrest as many Jews as the prisons could hold “especially rich ones”,
but to be careful that those arrested were healthy and not too old.
By 11 November 1938, 20,000 Jews had been arrested and many
were sent to concentration camps. On 24 January 1939 Heydrich,
the Chief of the Security Police and SD, was charged with furthering
the emigration and evacuation of Jews from Germany, and on 31
July 1941, with bringing about a complete solution of the Jewish
problem in German-dominated Europe. A special section of the
Gestapo office of the RSHA under Standartenführer Eichmann was
set up with responsibility for Jewish matters which employed its own
agents to investigate the Jewish problem in occupied territory. Local
offices of the Gestapo were used first to supervise the emigration of
Jews and later to deport them to the East both from Germany and
from the territories occupied during the war. Einsatzgruppen of the
Security Police and SD operating behind the lines of the Eastern
Front engaged in the wholesale massacre of Jews. A special
detachment from Gestapo headquarters in the RSHA was used to
arrange for the deportation of Jews from Axis satellites to Germany
for the “final solution”.
Local offices of the Security Police and SD played an important
role in the German administration of occupied territories. The nature
of their participation is shown by measures taken in the summer of
1938 in preparation for the attack on Czechoslovakia which was then
in contemplation. Einsatzgruppen of the Gestapo and SD were
organized to follow the Army into Czechoslovakia to provide for the
security of political life in the occupied territories. Plans were made
for the infiltration of SD men into the area in advance, and for the
building up of a system of files to indicate what inhabitants should
be placed under surveillance, deprived of passports, or liquidated.
These plans were considerably altered due to the cancellation of the
attack on Czechoslovakia, but in the military operations which
actually occurred, particularly in the war against U.S.S.R.,
Einsatzgruppen of the Security Police and SD went into operation,
and combined brutal measures for the pacification of the civilian
population with the wholesale slaughter of Jews. Heydrich gave
orders to fabricate incidents on the Polish-German frontier in 1939
which would give Hitler sufficient provocation to attack Poland. Both
Gestapo and SD personnel were involved in these operations.
The local units of the Security Police and SD continued their work
in the occupied territories after they had ceased to be an area of
operations. The Security Police and SD engaged in widespread
arrests of the civilian population of these occupied countries,
imprisoned many of them under inhumane conditions, subjected
them to brutal third degree methods, and sent many of them to
concentration camps. Local units of the Security Police and SD were
also involved in the shooting of hostages, the imprisonment of
relatives, the execution of persons charged as terrorists and
saboteurs without a trial, and the enforcement of the “Nacht und
Nebel” decrees under which persons charged with a type of offense
believed to endanger the security of the occupying forces were
either executed within a week or secretly removed to Germany
without being permitted to communicate with their family and
friends.
Offices of the Security Police and SD were involved in the
administration of the Slave Labor Program. In some occupied
territories they helped local labor authorities to meet the quotas
imposed by Sauckel. Gestapo offices inside of Germany were given
surveillance over slave laborers and responsibility for apprehending
those who were absent from their place of work. The Gestapo also
had charge of the so-called work training camps. Although both
German and foreign workers could be committed to these camps,
they played a significant role in forcing foreign laborers to work for
the German war effort. In the latter stages of the war as the SS
embarked on a slave labor program of its own, the Gestapo was
used to arrest workers for the purpose of insuring an adequate
supply in the concentration camps.
The local offices of the Security Police and SD were also involved
in the commission of War Crimes involving the mistreatment and
murder of prisoners of war. Soviet prisoners of war in prisoner-of-
war camps in Germany were screened by Einsatz Kommandos acting
under the directions of the local Gestapo offices. Commissars, Jews,
members of the intelligentsia, “fanatical Communists” and even
those who were considered incurably sick were classified as
“intolerable”, and exterminated. The local offices of the Security
Police and SD were involved in the enforcement of the “Bullet”
decree, put into effect on 4 March 1944, under which certain
categories of prisoners of war, who were recaptured, were not
treated as prisoners of war but taken to Mauthausen in secret and
shot. Members of the Security Police and SD were charged with the
enforcement of the decree for the shooting of parachutists and
commandos.

Conclusion

The Gestapo and SD were used for purposes which were criminal
under the Charter involving the persecution and extermination of the
Jews, brutalities, and killings in concentration camps, excesses in the
administration of occupied territories, the administration of the slave
labor program, and the mistreatment and murder of prisoners of
war. The Defendant Kaltenbrunner, who was a member of this
organization, was among those who used it for these purposes. In
dealing with the Gestapo the Tribunal includes all executive and
administrative officials of Amt IV of the RSHA or concerned with
Gestapo administration in other departments of the RSHA and all
local Gestapo officials serving both inside and outside of Germany,
including the members of the Frontier Police, but not including the
members of the Border and Customs Protection or the Secret Field
Police, except such members as have been specified above. At the
suggestion of the Prosecution the Tribunal does not include persons
employed by the Gestapo for purely clerical, stenographic, janitorial,
or similar unofficial routine tasks. In dealing with the SD the Tribunal
includes Ämter III, VI, and VII of the RSHA and all other members
of the SD, including all local representatives and agents, honorary or
otherwise, whether they were technically members of the SS or not,
but not including honorary informers who were not members of the
SS, and members of the Abwehr who were transferred to the SD.
The Tribunal declares to be criminal within the meaning of the
Charter the group composed of those members of the Gestapo and
SD holding the positions enumerated in the preceding paragraph
who became or remained members of the organization with
knowledge that it was being used for the commission of acts
declared criminal by Article 6 of the Charter, or who were personally
implicated as members of the organization in the commission of
such crimes. The basis for this finding is the participation of the
organization in War Crimes and Crimes against Humanity connected
with the war; this group declared criminal cannot include, therefore,
persons who had ceased to hold the positions enumerated in the
preceding paragraph prior to 1 September 1939.
SS
Structure and Component Parts: The Prosecution has named Die
Schutzstaffeln der Nationalsozialistischen Deutschen Arbeiterpartei
(commonly known as the SS) as an organization which should be
declared criminal. The portion of the Indictment dealing with the SS
also includes Der Sicherheitsdienst des Reichsführer-SS (commonly
known as the SD). This latter organization, which was originally an
intelligence branch of the SS, later became an important part of the
organization of Security Police and SD and is dealt with in the
Tribunal’s Judgment on the Gestapo.
The SS was originally established by Hitler in 1925 as an elite
section of the SA for political purposes under the pretext of
protecting speakers at public meetings of the Nazi Party. After the
Nazis had obtained power the SS was used to maintain order and
control audiences at mass demonstrations and was given the
additional duty of “internal security” by a decree of the Führer. The
SS played an important role at the time of the Röhm purge of 30
June 1934, and, as a reward for its services, was made an
independent unit of the Nazi Party shortly thereafter.
In 1929 when Himmler was first appointed as Reichs Führer the
SS consisted of 280 men who were regarded as especially
trustworthy. In 1933 it was composed of 52,000 men drawn from all
walks of life. The original formation of the SS was the Allgemeine SS,
which by 1939 had grown to a corps of 240,000 men, organized on
military lines into divisions and regiments. During the war its
strength declined to well under 40,000.
The SS originally contained two other formations, the SS
Verfügungstruppe, a force consisting of SS members who
volunteered for four years’ armed service in lieu of compulsory
service with the Army, and the SS Totenkopf Verbände, special
troops employed to guard concentration camps, which came under
the control of the SS in 1934. The SS Verfügungstruppe was
organized as an armed unit to be employed with the Army in the
event of mobilization. In the summer of 1939, the Verfügungstruppe
was equipped as a motorized division to form the nucleus of the
forces which came to be known in 1940 as the Waffen SS. In that
year the Waffen SS comprised 100,000 men, 56,000 coming from
the Verfügungstruppe and the rest from the Allgemeine SS and the
Totenkopf Verbände. At the end of the war it is estimated to have
consisted of about 580,000 men and 40 divisions. The Waffen SS
was under the tactical command of the Army, but was equipped and
supplied through the administrative branches of the SS and under SS
disciplinary control.
The SS Central Organization had 12 main offices. The most
important of these were the RSHA, which has already been
discussed, the WVHA or Economic Administration Main Office which
administered concentration camps along with its other duties, a Race
and Settlement Office together with auxiliary offices for repatriation
of racial Germans (Volksdeutschemittelstelle). The SS Central
Organization also had a legal office and the SS possessed its own
legal system; and its personnel were under the jurisdiction of special
courts. Also attached to the SS main offices was a research
foundation known as the Experiments Ahnenerbe. The scientists
attached to this organization are stated to have been mainly
honorary members of the SS. During the war an institute for military
scientific research became attached to the Ahnenerbe which
conducted extensive experiments involving the use of living human
beings. An employee of this institute was a certain Dr. Rascher, who
conducted these experiments with the full knowledge of the
Ahnenerbe, which were subsidized and under the patronage of the
Reichsführer SS who was a trustee of the foundation.
Beginning in 1933 there was a gradual but thorough
amalgamation of the police and SS. In 1936 Himmler, the
Reichsführer SS, became Chief of the German Police with authority
over the regular uniformed police as well as the Security Police.
Himmler established a system under which Higher SS and Police
Leaders, appointed for each Wehrkreis, served as his personal
representatives in coordinating the activities of the Order Police,
Security Police and SD and Allgemeine SS within their jurisdictions.
In 1939 the SS and police systems were coordinated by taking into
the SS all officials of the Security and Order Police, at SS ranks
equivalent to their rank in the police.
Until 1940 the SS was an entirely voluntary organization. After
the formation of the Waffen SS in 1940 there was a gradually
increasing number of conscripts into the Waffen SS. It appears that
about a third of the total number of people joining the Waffen SS
were conscripts, that the proportion of conscripts was higher at the
end of the war than at the beginning, but that there continued to be
a high proportion of volunteers until the end of the war.
Criminal Activities: SS units were active participants in the steps
leading up to aggressive war. The Verfügungstruppe was used in the
occupation of the Sudetenland, of Bohemia and Moravia, and of
Memel. The Henlein Free Corps was under the jurisdiction of the
Reichsführer SS for operations in the Sudetenland in 1938, and the
Volksdeutschemittelstelle financed fifth-column activities there.
The SS was even a more general participant in the commission of
War Crimes and Crimes against Humanity. Through its control over
the organization of the Police, particularly the Security Police and SD,
the SS was involved in all the crimes which have been outlined in the
section of this Judgment dealing with the Gestapo and SD. Other
branches of the SS were equally involved in these criminal programs.
There is evidence that the shooting of unarmed prisoners of war was
the general practice in some Waffen SS divisions. On 1 October 1944
the custody of prisoners of war and interned persons was
transferred to Himmler, who in turn transferred prisoner-of-war
affairs to SS Obergruppenführer Berger and to SS
Obergruppenführer Pohl. The Race and Settlement Office of the SS
together with the Volksdeutschemittelstelle were active in carrying
out schemes for Germanization of occupied territories according to
the racial principles of the Nazi Party and were involved in the
deportation of Jews and other foreign nationals. Units of the Waffen
SS and Einsatzgruppen operating directly under the SS main office
were used to carry out these plans. These units were also involved
in the widespread murder and ill-treatment of the civilian population
of occupied territories. Under the guise of combatting partisan units,
units of the SS exterminated Jews and people deemed politically
undesirable by the SS, and their reports record the execution of
enormous numbers of persons. Waffen SS divisions were responsible
for many massacres and atrocities in occupied territories such as the
massacres at Oradour and Lidice.
From 1934 onwards the SS was responsible for the guarding and
administration of concentration camps. The evidence leaves no
doubt that the consistently brutal treatment of the inmates of
concentration camps was carried out as a result of the general policy
of the SS, which was that the inmates were racial inferiors to be
treated only with contempt. There is evidence that where manpower
considerations permitted, Himmler wanted to rotate guard battalions
so that all members of the SS would be instructed as to the proper
attitude to take to inferior races. After 1942 when the concentration
camps were placed under the control of the WVHA they were used
as a source of slave labor. An agreement made with the Ministry of
Justice on 18 September 1942 provided that anti-social elements
who had finished prison sentences were to be delivered to the SS to
be worked to death. Steps were continually taken, involving the use
of the Security Police and SD and even the Waffen SS, to insure that
the SS had an adequate supply of concentration camp labor for its
projects. In connection with the administration of the concentration
camps, the SS embarked on a series of experiments on human
beings which were performed on prisoners of war or concentration
camp inmates. These experiments included freezing to death, and
killing by poison bullets. The SS was able to obtain an allocation of
Government funds for this kind of research on the grounds that they
had access to human material not available to other agencies.
The SS played a particularly significant role in the persecution of
the Jews. The SS was directly involved in the demonstrations of 10
November 1938. The evacuation of the Jews from occupied
territories was carried out under the directions of the SS with the
assistance of SS Police units. The extermination of the Jews was
carried out under the direction of the SS Central Organizations. It
was actually put into effect by SS formations. The Einstzgruppen
engaged in wholesale massacres of the Jews. SS Police units were
also involved. For example, the massacre of Jews in the Warsaw
ghetto was carried out under the directions of SS Brigadeführer and
Major General of the Police Stroop. A special group from the SS
Central Organization arranged for the deportation of Jews from
various Axis satellites and their extermination was carried out in the
concentration camps run by the WVHA.
It is impossible to single out any one portion of the SS which was
not involved in these criminal activities. The Allgemeine SS was an
active participant in the persecution of the Jews and was used as a
source of concentration camp guards. Units of the Waffen SS were
directly involved in the killing of prisoners of war and the atrocities in
occupied countries. It supplied personnel for the Einsatzgruppen,
and had command over the concentration camp guards after its
absorption of the Totenkopf SS, which originally controlled the
system. Various SS Police units were also widely used in the
atrocities in occupied countries and the extermination of the Jews
there. The SS Central Organization supervised the activities of these
various formations and was responsible for such special projects as
the human experiments and “final solution” of the Jewish question.
The Tribunal finds that knowledge of these criminal activities was
sufficiently general to justify declaring that the SS was a criminal
organization to the extent hereinafter described. It does appear that
an attempt was made to keep secret some phases of its activities,
but its criminal programs were so widespread, and involved
slaughter on such a gigantic scale, that its criminal activities must
have been widely known. It must be recognized, moreover, that the
criminal activities of the SS followed quite logically from the
principles on which it was organized. Every effort had been made to
make the SS a highly disciplined organization composed of the elite
of National Socialism. Himmler had stated that there were people in
Germany “who become sick when they see these black coats” and
that he did not expect that “they should be loved by too many.”
Himmler also indicated his view that the SS was concerned with
perpetuating the elite racial stock with the object of making Europe
a Germanic continent and the SS was instructed that it was designed
to assist the Nazi Government in the ultimate domination of Europe
and the elimination of all inferior races. This mystic and fanatical
belief in the superiority of the Nordic German developed into the
studied contempt and even hatred of other races which led to
criminal activities of the type outlined above being considered as a
matter of course if not a matter of pride. The actions of a soldier in
the Waffen SS who in September 1939, acting entirely on his own
initiative, killed 50 Jewish laborers whom he had been guarding,
were described by the statement that as an SS man, he was
“particularly sensitive to the sight of Jews,” and had acted “quite
thoughtlessly in a youthful spirit of adventure” and a sentence of
three-years imprisonment imposed on him was dropped under an
amnesty. Hess wrote with truth that the Waffen SS were more
suitable for the specific tasks to be solved in occupied territory owing
to their extensive training in questions of race and nationality.
Himmler, in a series of speeches made in 1943, indicated his pride in
the ability of the SS to carry out these criminal acts. He encouraged
his men to be “tough and ruthless”, he spoke of shooting “thousands
of leading Poles”, and thanked them for their cooperation and lack of
squeamishness at the sight of hundreds and thousands of corpses of
their victims. He extolled ruthlessness in exterminating the Jewish
race and later described this process as “delousing.” These speeches
show that the general attitude prevailing in the SS was consistent
with these criminal acts.
Conclusions: The SS was utilized for purposes which were
criminal under the Charter involving the persecution and
extermination of the Jews, brutalities and killings in concentration
camps, excesses in the administration of occupied territories, the
administration of the slave labor program and the mistreatment and
murder of prisoners of war. The Defendant Kaltenbrunner was a
member of the SS implicated in these activities. In dealing with the
SS the Tribunal includes all persons who had been officially accepted
as members of the SS including the members of the Allgemeine SS,
members of the Waffen SS, members of the SS Totenkopf Verbände,
and the members of any of the different police forces who were
members of the SS. The Tribunal does not include the so-called SS
riding units. Der Sicherheitsdienst des Reichsführer SS (commonly
known as the SD) is dealt with in the Tribunal’s Judgment on the
Gestapo and SD.
The Tribunal declares to be criminal within the meaning of the
Charter the group composed of those persons who had been
officially accepted as members of the SS as enumerated in the
preceding paragraph who became or remained members of the
organization with knowledge that it was being used for the
commission of acts declared criminal by Article 6 of the Charter, or
who were personally implicated as members of the organization in
the commission of such crimes, excluding, however, those who were
drafted into membership by the State in such a way as to give them
no choice in the matter, and who had committed no such crimes.
The basis of this finding is the participation of the organization in
War Crimes and Crimes against Humanity connected with the war;
this group declared criminal cannot include, therefore, persons who
had ceased to belong to the organizations enumerated in the
preceding paragraph prior to 1 September 1939.
THE SA
Structure and Component Parts: The Prosecution has named Die
Sturmabteilungen der Nationalsozialistischen Deutschen
Arbeiterpartei (commonly known as the SA) as an organization
which should be declared criminal. The SA was founded in 1921 for
political purposes. It was organized on military lines. Its members
wore their own uniforms and had their own discipline and
regulations. After the Nazis had obtained power the SA greatly
increased in membership due to the incorporation within it of certain
veterans organizations. In April 1933 the Stahlhelm, an organization
of 1½ million members, was transferred into the SA, with the
exception of its members over 45 years of age and some others,
pursuant to an agreement between their leader Seldte and Hitler.
Another veterans’ organization, the so-called Kyffhauserbund, was
transferred in the same manner, together with a number of rural
riding organizations.
Until 1933, there is no question but that membership in the SA
was voluntary. After 1933 civil servants were under certain political
and economic pressure to join the SA. Members of the Stahlhelm,
the Kyffhauserbund, and the rural riding associations were
transferred into the SA without their knowledge, but the Tribunal is
not satisfied that the members in general endeavored to protest
against this transfer or that there was any evidence, except in
isolated cases, of the consequences of refusal. The Tribunal
therefore finds that membership in the SA was generally voluntary.
By the end of 1933 the SA was composed of 4½ million men. As
a result of changes made after 1934, in 1939 the SA numbered 1½
million men.
Activities: In the early days of the Nazi movement the storm
troopers of the SA acted as the “strong arm of the Party”. They took
part in the beer hall feuds and were used for street-fighting in
battles against political opponents. The SA was also used to
disseminate Nazi ideology and propaganda and placed particular
emphasis on anti-Semitic propaganda, the doctrine of “Lebensraum”,
the revision of the Versailles Treaty, and the return of Germany’s
colonies.
After the Nazi advent to power, and particularly after the
elections of 5 March 1933, the SA played an important role in
establishing a Nazi reign of terror over Germany. The SA was
involved in outbreaks of violence against the Jews and was used to
arrest political opponents and to guard concentration camps, where
they subjected their prisoners to brutal mistreatment.
On 30 June and 1 and 2 July 1934 a purge of SA leaders
occurred. The pretext which was given for this purge, which involved
the killing of Röhm, the Chief of Staff of the SA, and many other SA
leaders, was the existence of a plot against Hitler. This purge
resulted in a great reduction in the influence and power of the SA.
After 1934, it rapidly declined in political significance.
After 1934 the SA engaged in certain forms of military or para-
military training. The SA continued to engage in the dissemination of
Nazi propaganda. Isolated units of the SA were even involved in the
steps leading up to aggressive war and in the commission of War
Crimes and Crimes against Humanity. SA units were among the first
in the occupation of Austria in March 1938. The SA supplied many of
the men and a large part of the equipment which composed the
Sudeten Free Corps of Henlein, although it appears that the corps
was under the jurisdiction of SS during its operation in
Czechoslovakia.
After the occupation of Poland, the SA group Sudeten was used
for transporting prisoners of war. Units of the SA were employed in
the guarding of prisoners in Danzig, Posen, Silesia, and the Baltic
States.
Some SA units were used to blow up synagogues in the Jewish
pogrom of 10 and 11 November 1938. Groups of the SA were
concerned in the ill-treatment of Jews in the ghettos of Vilna and
Kaunas.

Conclusion
Until the purge beginning on 30 June 1934, the SA was a group
composed in large part of ruffians and bullies who participated in the
Nazi outrages of that period. It has not been shown, however, that
these atrocities were part of a specific plan to wage aggressive war,
and the Tribunal therefore cannot hold that these activities were
criminal under the Charter. After the purge, the SA was reduced to
the status of a group of unimportant Nazi hangers-on. Although in
specific instances some units of the SA were used for the
commission of War Crimes and Crimes against Humanity, it cannot
be said that its members generally participated in or even knew of
the criminal acts. For these reasons the Tribunal does not declare
the SA to be a criminal organization within the meaning of Article 9
of the Charter.
THE REICH CABINET
The Prosecution has named as a criminal organization the Reich
Cabinet (Die Reichsregierung) consisting of members of the ordinary
cabinet after 30 January 1933, members of the Council of Ministers
for the Defense of the Reich and members of the Secret Cabinet
Council. The Tribunal is of opinion that no declaration of criminality
should be made with respect to the Reich Cabinet for two reasons:
(1) because it is not shown that after 1937 it ever really acted as a
group or organization; (2) because the group of persons here
charged is so small that members could be conveniently tried in
proper cases without resort to a declaration that the Cabinet of
which they were members was criminal.
As to the first reason for our decision, it is to be observed that
from the time that it can be said that a conspiracy to make
aggressive war existed the Reich Cabinet did not constitute a
governing body, but was merely an aggregation of administrative
officers subject to the absolute control of Hitler. Not a single meeting
of the Reich Cabinet was held after 1937, but laws were
promulgated in the name of one or more of the cabinet members.
The Secret Cabinet Council never met at all. A number of the cabinet
members were undoubtedly involved in the conspiracy to make
aggressive war; but they were involved as individuals and there is no
evidence that the Cabinet as a group or organization took any part in
these crimes. It will be remembered that when Hitler disclosed his
aims of criminal aggression at the Hossbach Conference, the
disclosure was not made before the Cabinet and that the Cabinet
was not consulted with regard to it, but, on the contrary, that it was
made secretly to a small group upon whom Hitler would necessarily
rely in carrying on the war. Likewise no cabinet order authorized the
invasion of Poland. On the contrary, the Defendant Schacht testifies
that he sought to stop the invasion by a plea to the Commander-in-
Chief of the Army that Hitler’s order was in violation of the
Constitution because not authorized by the Cabinet.
It does appear, however, that various laws authorizing acts which
were criminal under the Charter were circulated among the
members of the Reich Cabinet and issued under its authority signed
by the members whose departments were concerned. This does not,
however, prove that the Reich Cabinet, after 1937, ever really acted
as an organization.
As to the second reason, it is clear that those members of the
Reich Cabinet who have been guilty of crimes should be brought to
trial; and a number of them are now on trial before the Tribunal. It is
estimated that there are 48 members of the group, that eight of
these are dead and 17 are now on trial, leaving only 23 at the most,
as to whom the declaration could have any importance. Any others
who are guilty should also be brought to trial; but nothing would be
accomplished to expedite or facilitate their trials by declaring the
Reich Cabinet to be a criminal organization. Where an organization
with a large membership is used for such purposes, a declaration
obviates the necessity of inquiring as to its criminal character in the
later trial of members who are accused of participating through
membership in its criminal purposes and thus saves much time and
trouble. There is no such advantage in the case of a small group like
the Reich Cabinet.
GENERAL STAFF AND HIGH COMMAND
The Prosecution has also asked that the General Staff and High
Command of the German Armed Forces be declared a criminal
organization. The Tribunal believes that no declaration of criminality
should be made with respect to the General Staff and High
Command. The number of persons charged, while larger than that of
the Reich Cabinet, is still so small that individual trials of these
officers would accomplish the purpose here sought better than a
declaration such as requested. But a more compelling reason is that
in the opinion of the Tribunal the General Staff and High Command
is neither an “organization” nor a “group” within the meaning of
those terms as used in Article 9 of the Charter.
Some comment on the nature of this alleged group is requisite.
According to the Indictment and evidence before the Tribunal, it
consists of approximately 130 officers, living and dead, who at any
time during the period from February 1938, when Hitler reorganized
the Armed Forces, and May 1945, when Germany surrendered, held
certain positions in the military hierarchy. These men were high-
ranking officers in the three armed services: OKH—Army, OKM—
Navy, and OKL—Air Force. Above them was the overall Armed Forces
authority, OKW—High Command of the German Armed Forces with
Hitler as the Supreme Commander. The officers in OKW, including
Defendant Keitel as Chief of the High Command, were in a sense
Hitler’s personal staff. In the larger sense they coordinated and
directed the three services, with particular emphasis on the functions
of planning and operations.
The individual officers in this alleged group were, at one time or
another, in one of four categories: 1) Commanders-in-Chief of one of
the three services; 2) Chief of Staff of one of the three services; 3)
“Oberbefehlshabers”, the field Commanders-in-Chief of one of the
three services, which of course comprised by far the largest number
of these persons; or 4) an OKW officer, of which there were three,
Defendants Keitel and Jodl, and the latter’s Deputy Chief, Warlimont.
This is the meaning of the Indictment in its use of the term “General
Staff and High Command”.
The Prosecution has here drawn the line. The Prosecution does
not indict the next level of the military hierarchy consisting of
commanders of army corps, and equivalent ranks in the Navy and
Air Force, nor the level below, the division commanders or their
equivalent in the other branches. And the staff officers of the four
staff commands of OKW, OKH, OKM, and OKL are not included, nor
are the trained specialists who were customarily called General Staff
officers.
In effect, then, those indicted as members are military leaders of
the Reich of the highest rank. No serious effort was made to assert
that they composed an “organization” in the sense of Article 9. The
assertion is rather that they were a “group”, which is a wider and
more embracing term than “organization.”
The Tribunal does not so find. According to the evidence, their
planning at staff level, the constant conferences between staff
officers and field commanders, their operational technique in the
field and at headquarters was much the same as that of the armies,
navies, and air forces of all other countries. The over-all effort of
OKW at coordination and direction could be matched by a similar,
though not identical form of organization in other military forces,
such as the Anglo-American Combined Chiefs of Staff.
To derive from this pattern of their activities the existence of an
association or group does not, in the opinion of the Tribunal,
logically follow. On such a theory the top commanders of every other
nation are just such an association rather than what they actually
are, an aggregation of military men, a number of individuals who
happen at a given period of time to hold the high-ranking military
positions.
Much of the evidence and the argument has centered around the
question of whether membership in these organizations was or was
not voluntary; in this case, it seems to the Tribunal to be quite
beside the point. For this alleged criminal organization has one
characteristic, a controlling one, which sharply distinguishes it from
the other five indicted. When an individual became a member of the
SS for instance, he did so, voluntarily or otherwise, but certainly with
the knowledge that he was joining something. In the case of the
General Staff and High Command, however, he could not know he
was joining a group or organization for such organization did not
exist except in the charge of the Indictment. He knew only that he
had achieved a certain high rank in one of the three services, and
could not be conscious of the fact that he was becoming a member
of anything so tangible as a “group”, as that word is commonly used.
His relations with his brother officers in his own branch of the
service and his association with those of the other two branches
were, in general, like those of other services all over the world.
The Tribunal therefore does not declare the General Staff and
High Command to be a criminal organization.
Although the Tribunal is of the opinion that the term “group” in
Article 9 must mean something more than this collection of military
officers, it has heard much evidence as to the participation of the
officers in planning and waging aggressive war, and in committing
War Crimes and Crimes against Humanity. This evidence is, as to
many of them, clear and convincing.
They have been responsible in large measure for the miseries
and suffering that have fallen on millions of men, women, and
children. They have been a disgrace to the honorable profession of
arms. Without their military guidance the aggressive ambitions of
Hitler and his fellow Nazis would have been academic and sterile.
Although they were not a group falling within the words of the
Charter, they were certainly a ruthless military caste. The
contemporary German militarism flourished briefly with its recent
ally, National Socialism, as well as or better than it had in the
generations of the past.
Many of these men have made a mockery of the soldier’s oath of
obedience to military orders. When it suits their defense they say
they had to obey; when confronted with Hitler’s brutal crimes, which
are shown to have been within their general knowledge, they say
they disobeyed. The truth is they actively participated in all these
crimes, or sat silent and acquiescent, witnessing the commission of
crimes on a scale larger and more shocking than the world has ever
had the misfortune to know. This must be said.
Where the facts warrant it, these men should be brought to trial
so that those among them who are guilty of these crimes should not
escape punishment.
Article 26 of the Charter provides that the Judgment of the
Tribunal as to the guilt or innocence of any Defendant shall give the
reasons on which it is based.
The Tribunal will now state those reasons in declaring its
Judgment on such guilt or innocence.
GÖRING
Göring is indicted on all four Counts. The evidence shows that
after Hitler he was the most prominent man in the Nazi regime. He
was Commander-in-Chief of the Luftwaffe, Plenipotentiary for the
Four Year Plan, and had tremendous influence with Hitler, at least
until 1943 when their relationship deteriorated, ending in his arrest
in 1945. He testified that Hitler kept him informed of all important
military and political problems.

Crimes against Peace

From the moment he joined the Party in 1922 and took command
of the street-fighting organization, the SA, Göring was the adviser,
the active agent of Hitler, and one of the prime leaders of the Nazi
movement. As Hitler’s political deputy he was largely instrumental in
bringing the National Socialists to power in 1933, and was charged
with consolidating this power and expanding German armed might.
He developed the Gestapo, and created the first concentration
camps, relinquishing them to Himmler in 1934, conducted the Röhm
purge in that year, and engineered the sordid proceedings which
resulted in the removal of Von Blomberg and Von Fritsch from the
Army. In 1936 he became Plenipotentiary for the Four Year Plan, and
in theory and in practice was the economic dictator of the Reich.
Shortly after the Pact of Munich, he announced that he would
embark on a five-fold expansion of the Luftwaffe, and speed
rearmament with emphasis on offensive weapons.
Göring was one of the five important leaders present at the
Hossbach Conference of 5 November 1937, and he attended the
other important conferences already discussed in this Judgment. In
the Austrian Anschluss, he was indeed the central figure, the
ringleader. He said in Court: “I must take 100 percent
responsibility. . . . I even overruled objections by the Führer and
brought everything to its final development.” In the seizure of the
Sudetenland, he played his role as Luftwaffe chief by planning an air
offensive which proved unnecessary, and his role as politician by
lulling the Czechs with false promises of friendship. The night before
the invasion of Czechoslovakia and the absorption of Bohemia and
Moravia, at a conference with Hitler and President Hacha he
threatened to bomb Prague if Hacha did not submit. This threat he
admitted in his testimony.
Göring attended the Reich Chancellery meeting of 23 May 1939
when Hitler told his military leaders “there is, therefore, no question
of sparing Poland,” and was present at the Obersalzberg briefing of
22 August 1939. And the evidence shows he was active in the
diplomatic maneuvers which followed. With Hitler’s connivance, he
used the Swedish businessman, Dahlerus, as a go-between to the
British, as described by Dahlerus to this Tribunal, to try to prevent
the British Government from keeping its guarantee to the Poles.
He commanded the Luftwaffe in the attack on Poland and
throughout the aggressive wars which followed.
Even if he opposed Hitler’s plans against Norway and the Soviet
Union, as he alleged, it is clear that he did so only for strategic
reasons; once Hitler had decided the issue, he followed him without
hesitation. He made it clear in his testimony that these differences
were never ideological or legal. He was “in a rage” about the
invasion of Norway, but only because he had not received sufficient
warning to prepare the Luftwaffe offensive. He admitted he
approved of the attack: “My attitude was perfectly positive.” He was
active in preparing and executing the Yugoslavian and Greek
campaigns, and testified that “Plan Marita,” the attack on Greece,
had been prepared long beforehand. The Soviet Union he regarded
as the “most threatening menace to Germany,” but said there was
no immediate military necessity for the attack. Indeed, his only
objection to the war of aggression against the U.S.S.R. was its
timing; he wished for strategic reasons to delay until Britain was
conquered. He testified: “My point of view was decided by political
and military reasons only.”
After his own admissions to this Tribunal, from the positions
which he held, the conferences he attended, and the public words
he uttered, there can remain no doubt that Göring was the moving
force for aggressive war, second only to Hitler. He was the planner
and prime mover in the military and diplomatic preparation for war
which Germany pursued.

War Crimes and Crimes against Humanity

The record is filled with Göring’s admissions of his complicity in


the use of slave labor.
“We did use this labor for security reasons so that they
would not be active in their own country and would not
work against us. On the other hand, they served to help in
the economic war.”
And again:
“Workers were forced to come to the Reich. That is
something I have not denied.”
The man who spoke these words was Plenipotentiary for the Four
Year Plan charged with the recruitment and allocation of manpower.
As Luftwaffe Commander-in-Chief he demanded from Himmler more
slave laborers for his underground aircraft factories: “That I
requested inmates of concentration camps for the armament of the
Luftwaffe is correct and it is to be taken as a matter of course.”
As Plenipotentiary, Göring signed a directive concerning the
treatment of Polish workers in Germany and implemented it by
regulations of the SD, including “special treatment.” He issued
directives to use Soviet and French prisoners of war in the armament
industry; he spoke of seizing Poles and Dutch and making them
prisoners of war if necessary, and using them for work. He agrees
Russian prisoners of war were used to man anti-aircraft batteries.
As Plenipotentiary, Göring was the active authority in the
spoliation of conquered territory. He made plans for the spoliation of
Soviet territory long before the war on the Soviet Union. Two months
prior to the invasion of the Soviet Union, Hitler gave Göring the over-
all direction for the economic administration in the territory. Göring
set up an economic staff for this function. As Reichsmarshal of the
Greater German Reich, “the orders of the Reich Marshal cover all
economic fields, including nutrition and agriculture.” His so-called
“Green” folder, printed by the Wehrmacht, set up an “Economic
Executive Staff, East.” This directive contemplated plundering and
abandonment of all industry in the food deficit regions and, from the
food surplus regions, a diversion of food to German needs. Göring
claims its purposes have been misunderstood but admits “that as a
matter of course and a matter of duty we would have used Russia
for our purposes,” when conquered.
And he participated in the conference of 16 July 1941 when Hitler
said the National Socialists had no intention of ever leaving the
occupied countries, and that “all necessary measures—shooting,
desettling, etc.” should be taken.
Göring persecuted the Jews, particularly after the November
1938 riots, and not only in Germany where he raised the billion-mark
fine as stated elsewhere, but in the conquered territories as well. His
own utterances then and his testimony now shows this interest was
primarily economic—how to get their property and how to force
them out of the economic life of Europe. As these countries fell
before the German Army, he extended the Reich’s anti-Jewish laws
to them; the Reichsgesetzblatt for 1939, 1940, and 1941 contains
several anti-Jewish decrees signed by Göring. Although their
extermination was in Himmler’s hands, Göring was far from
disinterested or inactive, despite his protestations in the witness box.
By decree of 31 July 1941 he directed Himmler and Heydrich to
“bring about a complete solution of the Jewish question in the
German sphere of influence in Europe.”
There is nothing to be said in mitigation. For Göring was often,
indeed almost always, the moving force, second only to his leader.
He was the leading war aggressor, both as political and as military
leader; he was the director of the slave labor program and the
creator of the oppressive program against the Jews and other races,
at home and abroad. All of these crimes he has frankly admitted. On
some specific cases there may be conflict of testimony but in terms
of the broad outline, his own admissions are more than sufficiently
wide to be conclusive of his guilt. His guilt is unique in its enormity.
The record discloses no excuses for this man.

Conclusion

The Tribunal finds the Defendant Göring guilty on all four Counts
of the Indictment.
HESS
Hess is indicted under all four Counts. He joined the Nazi Party in
1920 and participated in the Munich Putsch on 9 November 1923. He
was imprisoned with Hitler in the Landsberg fortress in 1924 and
became Hitler’s closest personal confidant, a relationship which
lasted until Hess’ flight to the British Isles. On 21 April 1933 he was
appointed Deputy to the Führer, and on 1 December 1933 was made
Reichsminister without Portfolio. He was appointed member of the
Secret Cabinet Council on 4 February 1938, and a member of the
Ministerial Council for the Defense of the Reich on 30 August 1939.
In September 1939 Hess was officially announced by Hitler as
successor designate to the Führer after Göring. On 10 May 1941 he
flew from Germany to Scotland.

Crimes against Peace

As deputy to the Führer, Hess was the top man in the Nazi Party
with responsibility for handling all Party matters, and authority to
make decisions in Hitler’s name on all questions of Party leadership.
As Reichs Minister without Portfolio he had the authority to approve
all legislation suggested by the different Reichs Ministers before it
could be enacted as law. In these positions, Hess was an active
supporter of preparations for war. His signature appears on the law
of 16 March 1935 establishing compulsory military service.
Throughout the years he supported Hitler’s policy of vigorous
rearmament in many speeches. He told the people that they must
sacrifice for armaments, repeating the phrase, “Guns instead of
butter.” It is true that between 1933 and 1937 Hess made speeches
in which he expressed a desire for peace and advocated
international economic cooperation. But nothing which they
contained can alter the fact that of all the defendants none knew
better than Hess how determined Hitler was to realize his ambitions,
how fanatical and violent a man he was, and how little likely he was
to refrain from resort to force, if this was the only way in which he
could achieve his aims.
Hess was an informed and willing participant in German
aggression against Austria, Czechoslovakia, and Poland. He was in
touch with the illegal Nazi Party in Austria throughout the entire
period between the murder of Dollfuss, and the Anschluss, and gave
instructions to it during that period. Hess was in Vienna on 12 March
1938 when the German troops moved in; and on 13 March 1938 he
signed the law for the reunion of Austria within the German Reich. A
law of 10 June 1939 provided for his participation in the
administration of Austria. On 24 July 1938 he made a speech in
commemoration of the unsuccessful putsch by Austrian National
Socialists which had been attempted four years before, praising the
steps leading up to Anschluss and defending the occupation of
Austria by Germany.
In the summer of 1938 Hess was in active touch with Henlein,
Chief of the Sudeten German Party in Czechoslovakia. On 27
September 1938, at the time of the Munich crisis, he arranged with
Keitel to carry out the instructions of Hitler to make the machinery of
the Nazi Party available for a secret mobilization. On 14 April 1939
Hess signed a decree setting up the Government of the Sudetenland
as an integral part of the Reich; and an ordinance of 10 June 1939
provided for his participation in the administration of the
Sudetenland. On 7 November 1938 Hess absorbed Henlein’s Sudeten
German Party into the Nazi Party, and made a speech in which he
emphasized that Hitler had been prepared to resort to war if this had
been necessary to acquire the Sudetenland.
On 27 August 1939 when the attack on Poland had been
temporarily postponed in an attempt to induce Great Britain to
abandon its guarantee to Poland, Hess publicly praised Hitler’s
“magnanimous offer” to Poland, and attacked Poland for agitating
for war and England for being responsible for Poland’s attitude. After
the invasion of Poland Hess signed decrees incorporating Danzig and
certain Polish territories into the Reich, and setting up the General
Government (Poland).
These specific steps which this defendant took in support of
Hitler’s plans for aggressive action do not indicate the full extent of
his responsibility. Until his flight to England, Hess was Hitler’s closest
personal confidant. Their relationship was such that Hess must have
been informed of Hitler’s aggressive plans when they came into
existence. And he took action to carry out these plans whenever
action was necessary.
With him on his flight to England, Hess carried certain peace
proposals which he alleged Hitler was prepared to accept. It is
significant to note that this flight took place only 10 days after the
date on which Hitler fixed, 22 June 1941, as the time for attacking
the Soviet Union. In conversations carried on after his arrival in
England Hess wholeheartedly supported all Germany’s aggressive
actions up to that time, and attempted to justify Germany’s action in
connection with Austria, Czechoslovakia, Poland, Norway, Denmark,
Belgium, and the Netherlands. He blamed England and France for
the war.

War Crimes and Crimes against Humanity

There is evidence showing the participation of the Party


Chancellery, under Hess, in the distribution of orders connected with
the commission of War Crimes; that Hess may have had knowledge
of, even if he did not participate in, the crimes that were being
committed in the East, and proposed laws discriminating against
Jews and Poles; and that he signed decrees forcing certain groups of
Poles to accept German citizenship. The Tribunal, however, does not
find that the evidence sufficiently connects Hess with those crimes to
sustain a finding of guilt.
As previously indicated the Tribunal found, after a full medical
examination of and report on the condition of this defendant, that he
should be tried, without any postponement of his case. Since that
time further motions have been made that he should again be
examined. These the Tribunal denied, after having had a report from
the prison psychologist. That Hess acts in an abnormal manner,
suffers from loss of memory, and has mentally deteriorated during
this Trial, may be true. But there is nothing to show that he does not
realize the nature of the charges against him, or is incapable of
defending himself. He was ably represented at the Trial by counsel,
appointed for that purpose by the Tribunal. There is no suggestion
that Hess was not completely sane when the acts charged against
him were committed.

Conclusion

The Tribunal finds the Defendant Hess guilty on Counts One and
Two; and not guilty on Counts Three and Four.
VON RIBBENTROP
Von Ribbentrop is indicted under all four Counts. He joined the
Nazi Party in 1932. By 1933 he had been made Foreign Policy
Adviser to Hitler, and in the same year the representative of the Nazi
Party on foreign policy. In 1934 he was appointed Delegate for
Disarmament Questions, and in 1935 Minister Plenipotentiary at
Large, a capacity in which he negotiated the Anglo-German Naval
Agreement in 1935 and the Anti-Comintern Pact in 1936. On 11
August 1936 he was appointed Ambassador to England. On 4
February 1938 he succeeded Von Neurath as Reichsminister for
Foreign Affairs as part of the general reshuffle which accompanied
the dismissal of Von Fritsch and Von Blomberg.

Crimes against Peace

Von Ribbentrop was not present at the Hossbach Conference


held on 5 November 1937, but on 2 January 1938, while still
Ambassador to England, he sent a memorandum to Hitler indicating
his opinion that a change in the status quo in the East in the German
sense could only be carried out by force and suggesting methods to
prevent England and France from intervening in a European war
fought to bring about such a change. When Von Ribbentrop became
Foreign Minister Hitler told him that Germany still had four problems
to solve, Austria, Sudetenland, Memel, and Danzig, and mentioned
the possibility of “some sort of a show-down” or “military
settlement” for their solution.
On 12 February 1938 Von Ribbentrop attended the conference
between Hitler and Schuschnigg at which Hitler, by threats of
invasion, forced Schuschnigg to grant a series of concessions
designed to strengthen the Nazis in Austria, including the
appointment of Seyss-Inquart as Minister of Security and Interior,
with control over the police. Von Ribbentrop was in London when the
occupation of Austria was actually carried out and, on the basis of
information supplied him by Göring, informed the British
Government that Germany had not presented Austria with an
ultimatum, but had intervened in Austria only to prevent civil war. On
13 March 1938 Von Ribbentrop signed the law incorporating Austria
into the German Reich.
Von Ribbentrop participated in the aggressive plans against
Czechoslovakia. Beginning in March 1938, he was in close touch with
the Sudeten German Party and gave them instructions which had the
effect of keeping the Sudeten German question a live issue which
might serve as an excuse for the attack which Germany was
planning against Czechoslovakia. In August 1938 he participated in a
conference for the purpose of obtaining Hungarian support in the
event of a war with Czechoslovakia. After the Munich Pact he
continued to bring diplomatic pressure with the object of occupying
the remainder of Czechoslovakia. He was instrumental in inducing
the Slovaks to proclaim their independence. He was present at the
conference of 14-15 March 1939 at which Hitler, by threats of
invasion, compelled President Hacha to consent to the German
occupation of Czechoslovakia. After the German troops had marched
in, Von Ribbentrop signed the law establishing a protectorate over
Bohemia and Moravia.
Von Ribbentrop played a particularly significant role in the
diplomatic activity which led up to the attack on Poland. He
participated in a conference held on 12 August 1939, for the purpose
of obtaining Italian support if the attack should lead to a general
European war. Von Ribbentrop discussed the German demands with
respect to Danzig and the Polish Corridor with the British
Ambassador in the period from 25 August to 30 August 1939, when
he knew that the German plans to attack Poland had merely been
temporarily postponed in an attempt to induce the British to
abandon their guarantee to the Poles. The way in which he carried
out these discussions makes it clear that he did not enter them in
good faith in an attempt to reach a settlement of the difficulties
between Germany and Poland.
Von Ribbentrop was advised in advance of the attack on Norway
and Denmark and of the attack on the Low Countries, and prepared
the official Foreign Office memoranda attempting to justify these
aggressive actions.
Von Ribbentrop attended the conference on 20 January 1941, at
which Hitler and Mussolini discussed the proposed attack on Greece,
and the conference in January 1941, at which Hitler obtained from
Antonescu permission for German troops to go through Rumania for
this attack. On 25 March 1941, when Yugoslavia adhered to the Axis
Tripartite Pact, Von Ribbentrop had assured Yugoslavia that Germany
would respect its sovereignty and territorial integrity. On 27 March
1941 he attended the meeting, held after the coup d’état in
Yugoslavia, at which plans were made to carry out Hitler’s
announced intention to destroy Yugoslavia.
Von Ribbentrop attended a conference in May 1941 with Hitler
and Antonescu relating to Rumanian participation in the attack on
the U.S.S.R. He also consulted with Rosenberg in the preliminary
planning for the political exploitation of Soviet territories and in July
1941, after the outbreak of war, urged Japan to attack the Soviet
Union.

War Crimes and Crimes against Humanity

Von Ribbentrop participated in a meeting of 6 June 1944, at


which it was agreed to start a program under which Allied aviators
carrying out machine gun attacks on the civilian population should
be lynched. In December 1944 Von Ribbentrop was informed of the
plans to murder one of the French generals held as a prisoner of war
and directed his subordinates to see that the details were worked
out in such a way as to prevent its detection by the protecting
powers. Von Ribbentrop is also responsible for War Crimes and
Crimes against Humanity because of his activities with respect to
occupied countries and Axis satellites. The top German official in
both Denmark and Vichy France was a Foreign Office representative,
and Von Ribbentrop is therefore responsible for the general
economic and political policies put into effect in the occupation of
those countries. He urged the Italians to adopt a ruthless occupation
policy in Yugoslavia and Greece.
He played an important part in Hitler’s “final solution” of the
Jewish question. In September 1942 he ordered the German
diplomatic representatives accredited to various Axis satellites to
hasten the deportation of Jews to the East. In June 1942 the
German Ambassador to Vichy requested Laval to turn over 50,000
Jews for deportation to the East. On 25 February 1943 Von
Ribbentrop protested to Mussolini against Italian slowness in
deporting Jews from the Italian occupation zone of France. On 17
April 1943 he took part in a conference between Hitler and Horthy
on the deportation of Jews from Hungary and informed Horthy that
the “Jews must either be exterminated or taken to concentration
camps.” At the same conference Hitler had likened the Jews to
“tuberculosis bacilli” and said if they did not work they were to be
shot.
Von Ribbentrop’s defense to the charges made against him is
that Hitler made all the important decisions and that he was such a
great admirer and faithful follower of Hitler that he never questioned
Hitler’s repeated assertions that he wanted peace or the truth of the
reasons that Hitler gave in explaining aggressive action. The Tribunal
does not consider this explanation to be true. Von Ribbentrop
participated in all of the Nazi aggressions from the occupation of
Austria to the invasion of the Soviet Union. Although he was
personally concerned with the diplomatic rather than the military
aspect of these actions, his diplomatic efforts were so closely
connected with war that he could not have remained unaware of the
aggressive nature of Hitler’s actions. In the administration of
territories over which Germany acquired control by illegal invasion
Von Ribbentrop also assisted in carrying out criminal policies,
particularly those involving the extermination of the Jews. There is
abundant evidence, moreover, that Von Ribbentrop was in complete
sympathy with all the main tenets of the National Socialist creed,
and that his collaboration with Hitler and with other defendants in
the commission of Crimes against Peace, War Crimes, and Crimes
against Humanity was whole-hearted. It was because Hitler’s policy
and plans coincided with his own ideas that Von Ribbentrop served
him so willingly to the end.

Conclusion

The Tribunal finds that Von Ribbentrop is guilty on all four


Counts.

You might also like