C in a Nutshell 2 (Early Release) Edition Peter Prinz pdf download
C in a Nutshell 2 (Early Release) Edition Peter Prinz pdf download
Prinz download
https://ebookgate.com/product/c-in-a-nutshell-2-early-release-
edition-peter-prinz/
https://ebookgate.com/product/c-pocket-reference-1st-edition-
peter-prinz/
https://ebookgate.com/product/linux-kernel-in-a-nutshell-in-a-
nutshell-o-reilly-1st-edition-greg-kroah-hartman/
https://ebookgate.com/product/sql-in-a-nutshell-a-desktop-quick-
reference-guide-in-a-nutshell-o-reilly-3rd-edition-kevin-kline/
https://ebookgate.com/product/mysql-in-a-nutshell-1st-edition-
dyer/
Petlyakov Pe 2 First Edition Peter C Smith
https://ebookgate.com/product/petlyakov-pe-2-first-edition-peter-
c-smith/
https://ebookgate.com/product/web-design-in-a-nutshell-2nd-
edition-jennifer-niederst/
https://ebookgate.com/product/hbase-the-definitive-guide-2-early-
release-edition-lars-george/
https://ebookgate.com/product/php-in-a-nutshell-a-desktop-quick-
reference-1st-edition-paul-hudson/
https://ebookgate.com/product/administrative-law-and-process-in-
a-nutshell-6th-edition-ronald-levin/
SECOND EDITION
C in a Nutshell
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are regis‐
tered trademarks of O’Reilly Media, Inc. !!FILL THIS IN!! and related trade dress
are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their
products are claimed as trademarks. Where those designations appear in this
book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations
have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publish‐
er and authors assume no responsibility for errors or omissions, or for damages re‐
sulting from the use of the information contained herein.
ISBN: 063-6-920-03384-4
[?]
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
• Part I. Language
1. Language Basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Characteristics of C 3
The Structure of C Programs 4
Source Files 6
Comments 8
Character Sets 9
Wide Characters and Multibyte Characters 10
Universal Character Names 13
Digraphs and Trigraphs 14
Identifiers 15
Identifier Name Spaces 17
Identifier Scope 18
How the C Compiler Works 20
The C Compiler’s Translation Phases 21
Tokens 23
2. Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Typology 25
Integer Types 26
Integer Types Defined in Standard Headers 31
Floating-Point Types 33
Complex Floating-Point Types (C99) 35
Enumerated Types 36
The Type void 37
void in Function Declarations 38
Expressions of Type void 38
Pointers to void 38
iii
The Alignment of Objects in Memory 39
3. Literals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Integer Constants 41
Floating-Point Constants 42
Decimal Floating-Point Constants 42
Hexadecimal Floating-Point Constants 43
Character Constants 44
Types and Values of Character Constants 44
Escape Sequences 46
String Literals 48
4. Type Conversions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Conversion of Arithmetic Types 54
Hierarchy of Types 54
Integer Promotion 55
Usual Arithmetic Conversions 56
Other Implicit Type Conversions 58
The Results of Arithmetic Type Conversions 59
Conversion of Nonarithmetic Types 63
Array and Function Designators 63
Explicit Pointer Conversions 65
Implicit Pointer Conversions 67
Conversions Between Pointer and Integer Types 70
6. Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
iv Table of Contents
Expression Statements 109
Block Statements 110
Loops 111
while Statements 111
for Statements 112
do…while Statements 114
Nested Loops 115
Selection Statements 116
if Statements 116
switch Statements 117
Unconditional Jumps 119
The break Statement 119
The continue Statement 120
The goto Statement 121
The return Statement 123
7. Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Function Definitions 125
Functions and Storage Class Specifiers 126
K&R-Style Function Definitions 127
Function Parameters 128
Arrays as Function Parameters 128
The main() Function 130
Function Declarations 133
Declaring Optional Parameters 134
Declaring Variable-Length Array Parameters 134
How Functions Are Executed 135
Pointers as Arguments and Return Values 135
Inline Functions 137
Non-returning Functions 139
Recursive Functions 139
Variable Numbers of Arguments 141
8. Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Defining Arrays 143
Fixed-Length Arrays 144
Variable-Length Arrays 144
Accessing Array Elements 145
Initializing Arrays 146
Writing Initialization Lists 147
Initializing Specific Elements 148
Strings 149
Multidimensional Arrays 151
Matrices 151
Declaring Multidimensional Arrays 152
Table of Contents v
Initializing Multidimensional Arrays 152
Arrays as Arguments of Functions 153
9. Pointers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Declaring Pointers 157
Null Pointers 159
void Pointers 159
Initializing Pointers 160
Operations with Pointers 161
Using Pointers to Read and Modify Objects 161
Modifying and Comparing Pointers 163
Pointers and Type Qualifiers 165
Constant Pointers and Pointers to Constant Objects 166
Restricted Pointers 167
Pointers to Arrays and Arrays of Pointers 169
Array Pointers 170
Pointer Arrays 171
Pointers to Functions 174
vi Table of Contents
_Static_assert Declarations 208
Linkage of Identifiers 209
External Linkage 209
Internal Linkage 209
No Linkage 210
Storage Duration of Objects 211
Static Storage Duration 211
Thread Storage Duration 211
Automatic Storage Duration 211
Initialization 212
Implicit Initialization 212
Explicit Initialization 212
Table of Contents ix
The Floating-Point Environment 363
Error Handling 365
Character Classification and Conversion 366
Character Classification 367
Case Mapping 368
String Processing 369
Multibyte Characters 370
Converting Between Numbers and Strings 371
Searching and Sorting 373
Memory Block Handling 373
Dynamic Memory Management 374
Date and Time 374
Process Control 376
Communication with the Operating System 376
Signals 376
Internationalization 377
Nonlocal Jumps 378
Multithreading (C11) 378
Thread Functions 379
Atomic Operations 380
Debugging 382
Error Messages 383
x Table of Contents
Profiling 857
Option and Environment Variable Summary 858
Command-Line Options 858
Environment Variables 862
Table of Contents xi
Starting GDB 909
Command-Line Arguments 909
Command-Line Options 910
Initialization Files 913
Using GDB Commands 914
Command Completion 915
Displaying Help for Commands 915
Status Information 916
Running a Program in the Debugger 918
Displaying Source Code 920
Working with Breakpoints 921
Resuming Execution After a Break 925
Analyzing the Stack 928
Displaying Data 931
Watchpoints: Observing Operations on Variables 936
Analyzing Core Files in GDB 939
xiii
standard library; and the third part describes the process of compiling
and testing programs with the popular tools in the GNU software col‐
lection.
Part I
Part I, which deals with the C language, includes Chapter 1 through
14. After Chapter 1, which describes the general concepts and ele‐
ments of the language, each chapter is devoted to a specific topic,
such as types, statements, or pointers. Although the topics are or‐
dered so that the fundamental concepts for each new topic have been
presented in an earlier chapter—types, for example, are described be‐
fore expressions and operators, which come before statements, and so
on—you may sometimes need to follow references to later chapters to
fill in related details. For example, some discussion of pointers and ar‐
rays is necessary in Chapter 5 (which covers expressions and opera‐
tors), even though pointers and arrays are not described in full detail
until Chapter 8 and 9.
Chapter 1
Describes the characteristics of the language and how C programs
are structured and compiled. This chapter introduces basic con‐
cepts such as the translation unit, character sets, and identifiers.
Chapter 2
Provides an overview of types in C and describes the basic types,
the type void, and enumerated types.
Chapter 3
Describes numeric constants, character constants, and string liter‐
als, including escape sequences.
Chapter 4
Describes implicit and explicit type conversions, including integer
promotion and the usual arithmetic conversions.
Chapter 5
Describes the evaluation of expressions, all the operators, and
their compatible operands.
Chapter 6
Describes C statements such as blocks, loops, and jumps.
Chapter 7
Describes function definitions and function calls, including recur‐
sive and inline functions.
xiv Preface
Chapter 8
Describes fixed-length and variable-length arrays, including
strings, array initialization, and multidimensional arrays.
Chapter 9
Describes the definition and use of pointers to objects and func‐
tions.
Chapter 10
Describes the organization of data in these user-defined derived
types.
Chapter 11
Describes the general syntax of a declaration, identifier linkage,
and the storage duration of objects.
Chapter 12
Describes the standard library’s dynamic memory management
functions, illustrating their use in a sample implementation of a
generalized binary tree.
Chapter 13
Describes the C concept of input and output, with an overview of
the use of the standard I/O library.
Chapter 14
Describes the definition and use of macros, conditional compiling,
and all the other preprocessor directives and operators.
Part II
Part II, consisting of Chapter 15, 16, and 17, is devoted to the C stan‐
dard library. It provides an overview of standard headers and also
contains a detailed function reference.
Chapter 15
Describes contents of the headers and their use. The headers con‐
tain all of the standard library’s macros and type definitions.
(to come)
Provides an overview of the standard library functions, organized
by areas of application, such as “Mathematical Functions,” “Time
and Date Functions,” and so on.
Chapter 17
Describes each standard library function in detail, in alphabetical
order, and contains examples to illustrate the use of each function.
Preface xv
Part III
The third part of this book provides the necessary knowledge of the C
programmer’s basic tools: the compiler, the make utility, and the de‐
bugger. The tools described here are those in the GNU software col‐
lection.
Chapter 18
Describes the principal capabilities that the widely used compiler
offers for C programmers.
Chapter 19
Describes how to use the make program to automate the compiling
process for large programs.
(to come)
Describes how to run a program under the control of the GNU de‐
bugger and how to analyze programs’ runtime behavior to find log‐
ical errors.
Further Reading
In addition to works mentioned at appropriate points in the text, there
are a number of resources for readers who want more technical detail
than even this book can provide. The international working group on
C standardization has an official home page at http://www.open-
std.org/jtc1/sc22/wg14, with links to the latest version of the C99
standard and current projects of the working group.
For readers who are interested in not only the what and how of C, but
also the why, the WG14 site also has a link to the “C99 Rationale”:
this is a nonnormative but current document that describes some of
the motivations and constraints involved in the standardization pro‐
cess. The C89 Rationale is online at http://www.lysator.liu.se/c/rat/
title.html. Furthermore, for those who may wonder how C “got to be
that way” in the first place, the originator of C, Dennis Ritchie, has an
article titled “The Development of the C Language” as well as other
historical documents on his Bell Labs web site, http://cm.bell-
labs.com/cm/cs/who/dmr.
Readers who want details on floating-point math beyond the scope of
C may wish to start with David Goldberg’s thorough introduction,
“What Every Computer Scientist Should Know About Floating-Point
Arithmetic,” currently available online at http://docs.sun.com/source/
806-3568/ncg_goldberg.html.
xvi Preface
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic
Highlights new terms; indicates filenames, file extensions, URLs,
directories, and Unix utilities.
Constant width
Indicates all elements of C source code: keywords, operators, vari‐
ables, functions, macros, types, parameters, and literals. Also used
for console commands and options, and the output from such com‐
mands.
Constant width bold
Highlights the function or statement under discussion in code ex‐
amples. In compiler, make, and debugger sessions, this font indi‐
cates command input to be typed literally by the user.
Constant width italic
Indicates parameters in function prototypes, or placeholders to be
replaced with your own values.
Plain text
Indicates keys such as Return, Tab, and Ctrl.
Preface xvii
We appreciate, but do not require, attribution. An attribution usually
includes the title, author, publisher, and ISBN. For example: "C in a
Nutshell by Peter Prinz and Tony Crawford. Copyright 2006 O’Reilly
Media, Inc., 0-596-00697-7.”
If you feel that your use of code examples falls outside fair use or the
permission given here, feel free to contact us at <permissions@oreil
ly.com>.
How to Contact Us
Please address comments and questions concerning this book to the
publisher:
O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)
xviii Preface
We have a web page for this book, where we list errata, examples, and
any additional information. You can access this page at http://
www.oreilly.com/catalog/<catalog page>.
To comment or ask technical questions about this book, send email to
<[email protected]>.
For more information about our books, courses, conferences, and
news, see our website at http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia
Acknowledgments
Both of us want to thank Jonathan Gennick, our editor, for originally
bringing us together and starting us off on this book, and for all his
guidance along the way. We also thank our technical reviewers, Matt
Crawford, David Kitabjian, and Chris LaPre, for their valuable criti‐
cism of our manuscript, and we’re grateful to our production editor,
Abby Fox, for all her attention to making our book look good.
Peter
I would like to thank Tony first of all for the excellent collaboration.
My heartfelt thanks also go to all my friends for the understanding
they showed again and again when I had so little time for them. Last
but not least, I dedicate this book to my daughters, Vivian and Jea‐
nette—both of them now students of computer science—who strength‐
ened my ambition to carry out this book project.
Tony
I have enjoyed working on this book as a very rewarding exercise in
teamwork. I thank Peter for letting me take all the space I could fill in
this project.
Preface xix
PART I
Language
Chapter 1
Language Basics
Characteristics of C
C is a general-purpose, procedural programming language. Dennis
Ritchie first devised C in the 1970s at AT&T Bell Laboratories in Mur‐
ray Hill, New Jersey, for the purpose of implementing the Unix operat‐
ing system and utilities with the greatest possible degree of independ‐
ence from specific hardware platforms. The key characteristics of the
C language are the qualities that made it suitable for that purpose:
As a result, the developers of Unix were able to write most of the op‐
erating system in C, leaving only a minimum of system-specific hard‐
ware manipulation to be coded in assembler.
C’s ancestors are the typeless programming languages BCPL (the Ba‐
sic Combined Programming Language), developed by Martin Ri‐
chards; and B, a descendant of BCPL, developed by Ken Thompson. A
new feature of C was its variety of data types: characters, numeric
types, arrays, structures, and so on. Brian Kernighan and Dennis
Ritchie published an official description of the C programming lan‐
guage in 1978. As the first de facto standard, their description is com‐
3
monly referred to simply as “K&R.”1 C owes its high degree of porta‐
bility to a compact core language that contains few hardware-
dependent elements. For example, the C language proper has no file
access or dynamic memory management statements. In fact, there
aren’t even any statements for console input and output. Instead, the
extensive standard C library provides the functions for all of these
purposes.
This language design makes the C compiler relatively compact and
easy to port to new systems. Furthermore, once the compiler is run‐
ning on a new system, you can compile most of the functions in the
standard library with no further modification, because they are in turn
written in portable C. As a result, C compilers are available for practi‐
cally every computer system.
Because C was expressly designed for system programming, it is hard‐
ly surprising that one of its major uses today is in programming em‐
bedded systems. At the same time, however, many developers use C
as a portable, structured high-level language to write programs such
as powerful word processor, database, and graphics applications.
1. The second edition, revised to reflect the first ANSI C standard, is available as The
C Programming Language, 2nd ed., by Brian W. Kernighan and Dennis M. Ritchie
(Englewood Cliffs, N.J.: Prentice Hall, 1988).
radius = 5.0;
area = circularArea( radius );
printf( "%10.1f %10.2f\n", radius, area );
return 0;
}
Output:
Areas of Circles
Radius Area
-------------------------
Source Files
The function definitions, global declarations and preprocessing direc‐
tives make up the source code of a C program. For small programs,
the source code is written in a single source file. Larger C programs
consist of several source files. Because the function definitions gener‐
ally depend on preprocessor directives and global declarations, source
files usually have the following internal structure:
1. Preprocessor directives
2. Global declarations
3. Function definitions
#include <stdio.h>
double circularArea( double r );
int main()
{
/* ... As in Example 1-1... */
}
Source Files 7
self, and no characters except spaces or tabs may precede the hash
mark (#) that begins the line.
There are many different conventions and “house styles” for source
code formatting. Most of them include the following common rules:
Comments
You should use comments generously in the source code to document
your C programs. There are two ways to insert a comment in C: block
comments begin with /* and end with */, and line comments begin
with // and end with the next new line character.
You can use the /* and */ delimiters to begin and end comments with‐
in a line, and to enclose comments of several lines. For example, in
the following function prototype, the ellipsis (…) signifies that the
open() function has a third, optional parameter. The comment ex‐
plains the usage of the optional parameter:
int open( const char *name, int mode, ... /* int permissions
*/ );
You can use // to insert comments that fill an entire line, or to write
source code in a two-column format, with program code on the left
and comments on the right:
const double pi = 3.1415926536; // Pi is constant
The only thing that the preprocessor looks for in examining the char‐
acters in a comment is the end of the comment; thus it is not possible
to nest block comments. However, you can insert /* and */ to com‐
ment out part of a program that contains line comments:
Character Sets
C makes a distinction between the environment in which the compiler
translates the source files of a program—the translation environment
—and the environment in which the compiled program is executed,
the execution environment. Accordingly, C defines two character sets:
the source character set is the set of characters that may be used in C
source code, and the execution character set is the set of characters
that can be interpreted by the running program. In many C implemen‐
tations, the two character sets are identical. If they are not, then the
compiler converts the characters in character constants and string lit‐
erals in the source code into the corresponding elements of the execu‐
tion character set.
Each of the two character sets includes both a basic character set and
extended characters. The C language does not specify the extended
characters, which are usually dependent on the local language. The
extended characters together with the basic character set make up
the extended character set.
The basic source and execution character sets both contain the follow‐
ing types of characters:
The letters of the Latin alphabet
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m n o p q r s t u v w x y z
The decimal digits
0 1 2 3 4 5 6 7 8 9
The following 29 punctuation marks
! " # % & ' () * + , − . / : ; < = > ? [ \ ] ^ _ { | } ~
Character Sets 9
The five whitespace characters
Space, horizontal tab, vertical tab, new line, and form feed
The basic execution character set also includes four nonprintable
characters : the null character, which acts as the termination mark in
a character string; alert; backspace; and carriage return. To represent
these characters in character and string literals, type the correspond‐
ing escape sequences beginning with a backslash: \0 for the null char‐
acter, \a for alert, \b for backspace, and \r for carriage return. See
Chapter 3 for more details.
The actual numeric values of characters—the character codes —may
vary from one C implementation to another. The language itself impo‐
ses only the following conditions:
• wide characters, in which the same bit width is used for every
character in a character set, and
• multibyte characters, in which a given character can be represent‐
ed by one or several bytes, and the character value of a given byte
sequence can depend on its context in a string or stream.
Wide Characters
Since the 1994 addendum, C has provided not only the type char, but
also wchar_t, the wide character type. This type, defined in the head‐
er file stddef.h, is large enough to represent any element of the given
implementation’s extended character sets.
Although the C standard does not require support for Unicode charac‐
ter sets, many implementations use the Unicode transformation for‐
mats UTF-16 and UTF-32 (see http://www.unicode.org/) for wide char‐
acters. The Unicode standard is largely identical with the ISO/IEC
10646 standard, and is a superset of many previously existing charac‐
ter sets, including the 7-bit ASCII code. When the Unicode standard is
implemented, the type wchar_t is at least 16 or 32 bits wide, and a
value of type wchar_t represents one Unicode character. For example,
the following definition initializes the variable wc with the Greek letter
α.
wchar_t wc = '\x3b1';
Character Sets 11
basic character set occupies only one byte, and no multibyte character
except the null character may contain any byte in which all bits are 0.
Multibyte characters can be used in character constants, string liter‐
als, identifiers, comments, and header filenames. Many multibyte
character sets are designed to support a certain language, such as the
Japanese Industrial Standard character set (JIS). The multibyte UTF-8
character set, defined by the Unicode Consortium, is capable of repre‐
senting all Unicode characters. UTF-8 uses from one to four bytes to
represent a character.
The key difference between multibyte characters and wide characters
(that is, characters of the type wchar_t, char16_t or char32_t) is that
wide characters are all the same size, and multibyte characters are
represented by varying numbers of bytes. This representation makes
multibyte strings more complicated to process than strings of wide
characters. For example, even though the character A can be repre‐
sented in a single byte, finding it in a multibyte string requires more
than a simple byte-by-byte comparison, because the same byte value
in certain locations could be part of a different character. Multibyte
characters are well suited for saving text in files, however (see Chap‐
ter 13). Furthermore, the encoding of multibyte characters is inde‐
pendent of the system architecture, while encoding of wide characters
is dependent on the given system’s byte order: that is, the bytes of a
wide character may be in big-endian or little-endian order, depending
on the system.
Conversion
C provides standard functions to obtain the wchar_t value of any mul‐
tibyte character, and to convert any wide character to its multibyte
representation. For example, if the C compiler uses the Unicode
standards UTF-16 and UTF-8, then the following call to the function
wctomb() (read: “wide character to multibyte”) obtains the multibyte
representation of the character α:
wchar_t wc = L'\x3B1'; // Greek lower-case alpha,α
char mbStr[10] = "";
int nBytes = 0;
nBytes = wctomb( mbStr, wc );
if( nBytes < 0)
puts("Not a valid multibyte character in your locale.");
After a successful function call, the array mbStr contains the multibyte
character, which in this example is the sequence "\xCE\xB1". The
wctomb() function’s return value, assigned here to the variable
nBytes, is the number of bytes required to represent the multibyte
character, namely 2.
or:
\UXXXXXXXX
Character Sets 13
Digraphs and Trigraphs
C provides alternative representations for a number of punctuation
marks that are not available on all keyboards. Six of these are the di‐
graphs, or two-character tokens, which represent the characters
shown in Table 1-1.
Table 1-1. Digraphs
Digraph Equivalent
<: [
:> ]
<% {
%> }
%: #
%:%: ##
Without digraphs:
int arr[] = { 10, 20, 30 };
printf( "The second array element is <%d>.\n", arr[1] );
Output:
The second array element is .
Trigraphs allow you to write any C program using only the characters
defined in ISO/IEC 646, the 1991 standard corresponding to 7-bit AS‐
CII. The compiler’s preprocessor replaces the trigraphs with their
single-character equivalents in the first phase of compilation. This
means that the trigraphs, unlike digraphs, are translated into their
single-character equivalents no matter where they occur, even in
character constants, string literals, comments, and preprocessing di‐
rectives. For example, the preprocessor interprets the statement’s
second and third question marks below as the beginning of a trigraph:
printf("Cancel???(y/n) ");
If the character following any two question marks is not one of those
shown in Table 1-2, then the sequence is not a trigraph, and remains
unchanged.
Identifiers
The term identifier refers to the names of variables, functions, mac‐
ros, structures and other objects defined in a C program. Identifiers
can contain the following characters:
• The letters in the basic character set, a-z and A-Z. Identifiers are
case-sensitive.
Identifiers 15
• The underscore character, _.
• The decimal digits 0-9, although the first character of an identifier
must not be a digit.
• Universal character names that represent the letters and digits of
other languages.
Your source code editor might save the character α in the source file
as the universal character \u03B1.
• Label names.
• Tags, which identify structure, union and enumeration types.
• Names of structure or union members. Each structure or union
constitutes a separate name space for its members.
• All other identifiers, which are called ordinary identifiers.
Identifiers 17
Identifiers that belong to different name spaces may be the same
without causing conflicts. In other words, you can use the same name
to refer to different objects, if they are of different kinds. For example,
the compiler is capable of distinguishing between a variable and a la‐
bel with the same name. Similarly, you can give the same name to a
structure type, an element in the structure, and a variable, as the fol‐
lowing example shows:
struct pin { char pin[16]; /* ... */ };
_Bool check_pin( struct pin *pin )
{
int len = strlen( pin->pin );
/* ... */
}
The first line of the example defines a structure type identified by the
tag pin, containing a character array named pin as one of its mem‐
bers. In the second line, the function parameter pin is a pointer to a
structure of the type just defined. The expression pin->pin in the
fourth line designates the member of the structure that the function’s
parameter points to. The context in which an identifier appears always
determines its name space with no ambiguity. Nonetheless, it is gen‐
erally a good idea to make all identifiers in a program distinct, in or‐
der to spare human readers unnecessary confusion.
Identifier Scope
The scope of an identifier refers to that part of the translation unit in
which the identifier is meaningful. Or to put it another way, the identi‐
fier’s scope is that part of the program that can “see” that identifier.
The type of scope is always determined by the location at which you
declare the identifier (except for labels, which always have function
scope ). Four kinds of scope are possible:
File scope
If you declare an identifier outside all blocks and parameter lists,
then it has file scope. You can then use the identifier anywhere af‐
ter the declaration and up to the end of the translation unit.
Block scope
Except for labels, identifiers declared within a block have block
scope. You can use such an identifier only from its declaration to
the end of the smallest block containing that declaration. The
smallest containing block is often, but not necessarily, the body of
a function definition. In C99, declarations do not have to be placed
before all statements in a function block. The parameter names in
the head of a function definition also have block scope, and are
valid within the corresponding function block.
In this code snippet, the identifiers Node, next, printNode, and print
List all have file scope. The parameter ptrNode has function proto‐
type scope, and the variables first and ptr have block scope.
It is possible to use an identifier again in a new declaration nested
within its existing scope, even if the new identifier does not have a dif‐
Identifiers 19
ferent name space. If you do so, then the new declaration must have
block or function prototype scope, and the block or function prototype
must be a true subset of the outer scope. In such cases, the new decla‐
ration of the same identifier hides the outer declaration, so that the
variable or function declared in the outer block is not visible in the in‐
ner scope. For example, the following declarations are permissible:
double x; // Declare a variable x with file scope
long calc( double x ); // Declare a new x with function proto‐
type scope
int main()
{
long x = calc( 2.5 ); // Declare a long variable x with
block scope
1. Characters are read from the source file and converted, if necessa‐
ry, into the characters of the source character set. The end-of-line
indicators in the source file, if different from the new line charac‐
ter, are replaced. Likewise, any trigraph sequences are replaced
3. The source file is broken down into preprocessor tokens (see the
next section, “Tokens” (page 23)) and sequences of whitespace
characters. Each comment is treated as one space.
4. The preprocessor directives are carried out and macro calls are
expanded.
Tokens
A token is either a keyword, an identifier, a constant, a string literal,
or a symbol. Symbols in C consist of one or more punctuation charac‐
ters, and function as operators or digraphs, or have syntactic impor‐
tance, like the semicolon that terminates a simple statement, or the
braces { } that enclose a block statement. For example, the following
C statement consists of five tokens:
printf("Hello, world.\n");
In parsing the source file into tokens, the compiler (or preprocessor)
always applies the following principle: each successive non-
whitespace character must be appended to the token being read, un‐
less appending it would make a valid token invalid. This rule resolves
any ambiguity in the following expression, for example:
a+++b
It has often been affirmed that "'Lincoln knew his Bible better than
any minister," and large claims have been made concerning his use
of it in public addresses. Mr. Lincoln did know and use the Bible, and
his style is saturated with it; but it would be easy to exaggerate both
his knowledge and use of it.
Prof. Daniel Kilham Dodge of the University of Illinois examined
twenty-five of Lincoln's extended and carefully prepared addresses
with this result:[61]
In five speeches from 1839 to 1852 he found six Biblical quotations,
of which four were in his temperance address.
In his reply to Douglas in 1852 there were two Biblical quotations,
both from the Old Testament.
In 1856 he found one, and that most notable of all—the "house
divided against itself."
In his "lost speech" at Bloomington, as recorded by Whitney, there
were six Biblical quotations, four from the Old Testament and two
from the New—the largest number in any single speech.
In his ten speeches in the Lincoln and Douglas debates there were
two Biblical references, besides a number of allusions to the "house
divided against itself."
There were no Biblical quotations in the Cooper Union address or in
the First Inaugural or in the Gettysburg address; none in the two
messages to Congress in 1861.
His Second Inaugural was itself a kind of leaf out of the books of the
prophets.
In the whole of the twenty-five speeches, there were found twenty-
two Biblical references, eight in the Old Testament and fourteen in
the New. This notwithstanding the impression of many who knew
him that Lincoln preferred the Old Testament to the New, as
recorded by Noah Brooks.
But this rather meager use of direct quotations and allusions need
not disappoint us. Nor does it militate against the essentially Biblical
substratum of his style. When we come to the study of Lincoln's
literary and oratorical method, we find more striking contradictions
and evolutions than we have here. Lincoln's oratory was not of the
same style at all periods of his career, nor were his methods uniform
at any one period.
He was a ready stump-speaker, yet he became so cautious while in
the White House that he was timid about responding even to a
serenade without having first written out his address, and on
occasion could appear rude in declining to utter even a simple word
of greeting and appreciation, as on the night before his address in
Gettysburg, when he was very abrupt to the company that
serenaded him.
He had been accustomed to large use of gesture, swinging his great
arms, and sometimes, even in the Douglas debates, bending his
knees till they almost touched the platform, and then rising suddenly
almost with a whoop, but he became very quiet and self-restrained
in his oratory.
He is alleged to have loved Burns more than any other poet, yet his
speeches have been searched in vain for a single quotation from
Burns. It is said that next to Burns he loved Byron, and he is not
known ever to have quoted Byron in any speech or paper. It is said
that his favorite Shakspeare play was Richard III., but his
Shakspeare quotations are from Hamlet, Lear, Macbeth, the
Merchant of Venice; and there is one allusion to Falstaff.
Besides Shakspeare, whom he quoted next to the Bible, his literary
allusions are to T. H. Bayley, Dickens, Robert Herrick, Pope and
Scott, and they are not numerous. The total number of his
quotations, as listed by Professor Dodge, including Shakspeare, but
not including the Bible, is thirty.
What is more surprising, Lincoln was known as a great story teller.
But his addresses contain hardly a single anecdote. He told stories in
jury trials and to illustrate points in conversation, but he rarely told
them in his addresses.[62]
No man who knew Lincoln intimately studied him so long, so
industriously, or, in spite of many limitations, so appreciatively, as
William H. Herndon. He was a profound believer in the mental and
spiritual evolution of Lincoln.
In 1887, while Herndon, after many years of interruption, began
again the preparation of his Life of Lincoln, he had an extended
correspondence, partly from Springfield, and partly from
Greencastle, Indiana, where Mr. Jesse W. Weik was at work with him
on his book, and with a Boston sculptor, Mr. Truman H. Bartlett, who
was planning a statue of Lincoln. Herndon's letters went more and
more into detail as the correspondence proceeded, and he gave in
some respects the very best affirmation of the development of
Lincoln on the higher side of his nature that Herndon wrote at any
time.
Herndon seemed to have some apprehension that a study of
photographs and life-masks and other evidences of the physical
appearance of Lincoln would not reveal the man himself. He said
that a person studying his physical nature would say "that his
physical nature was low, coarse, and not high and fine." Before he
sent this letter he re-read it, and inserted the word "comparatively"
before "low." Mr. Bartlett asked him further about this, and Herndon
went into detail as to Lincoln's body. "His blood ran slowly. He was of
a low or slow mechanical power, within him. I did not intend to say
that Lincoln's organization was a low, animal organization. What I
meant to say was that it was a slow-working machine. Lincoln's flesh
was coarse, pimply, dry, hard, harsh; color of his flesh saffron
brown; no blood seemingly in it; flesh wrinkled."
Mr. Bartlett apparently inquired whether the abnormal qualities of
frontier life produced these effects, and whether Herndon had
known other men of the Lincoln type. Apparently he alluded to the
presence of malaria and the large use of pork in frontier diet.
Herndon did not accept the pork and malaria theories. He said that
all such theories must give way to facts, and he dealt with facts. The
men of the frontier had the best meat in the world, "venison, bear,
turkey, and of course some hog."
"You ask me if I ever saw in this great wild west many men of
Lincoln's type, and to which I answer, Yes. The first settlers of
central and southern Illinois were men of that type. They came
from the limestone regions of Virginia, Kentucky, and
Tennessee, and were men of giant strength, physical force, and
by nature mentally strong. They were original, were
individualists. The strong alone from 1818 to 1830 could get
here, and the strong alone could survive here.... No one was
like Lincoln, and yet many were of his type.... He was, as you
say, 'a man of extraordinary contrasts.' You would not look for a
well-rounded man in such a description."
Lincoln was, then, as Herndon saw him, and as the world must see
him, a legitimate product of his environment. Herndon had read
Buckle and Spencer and Darwin, and was a thoroughgoing believer
in evolution, as was Lincoln, from a far narrower reading, but a very
thoughtful study of Vestiges of Creation.
Physically, Lincoln was akin to the strong pioneers of early Illinois,
and it was not difficult to find each several trait of Lincoln
reduplicated in many of them. But Lincoln himself was never
duplicated. He was a product of his environment, but he was also an
evolution which in terms of an individual personality went beyond
environment, and was still going forward when death came to him.
This evolution of Lincoln, the spiritual Lincoln, as portrayed in these
letters to a sculptor, who must not be permitted to forget, if he was
in danger of forgetting, that the real man Lincoln had in him more
than his bodily measurements could portray, is one of the most
suggestive studies disclosed by Herndon, and it is sound, both as
approached from the standpoint of science, and as considered in the
personal study of Lincoln in his growth from year to year.
Like St. Paul, Lincoln had a warfare in his members. He was an
embodiment of forces mutually antagonistic. He would not have
been the man he was had either of them been lacking, and the
growth of either at the total expense of the other would have given
us a man abnormal, which Mr. Lincoln came perilously near to being.
But his real development was mental and spiritual.
In another place St. Paul says that "The first man is of the earth,
earthy, and the second man is from heaven." It has been assumed
without due warrant that what he had in mind was a contrast
between Adam and Christ, and this view is strengthened by the
intrusion of the words "the Lord" in the authorized English text. But
it is quite possible that St. Paul, even if Adam and Christ were a part
of his contrast, had really in mind the evolution of any man's life; he
being himself in his bodily nature the first man and in the birth and
growth of his higher nature the second and contrasting man. "First is
that which is natural, and after, that which is spiritual."
This was Herndon's thought of Lincoln, as disclosed in these letters,
[63] and it is true of Lincoln. Lincoln was more than an embodiment
of contrasts; the solar system is that, and it is more. In the solar
system the opposing forces do not neutralize each other, but
together hold the earth and planets in their orbits. So it was with
Lincoln. But with him the higher and nobler forces became
increasingly dominant.
Herndon resented it when anyone said that Lincoln had died at the
right time. He believed that, great as Lincoln was, his nobler
qualities had not yet come to their full maturity, and that a longer-
lived Lincoln would have been an even nobler Lincoln. Here are
some of the things he says of him in these letters:
"I said to you once that Mr. Lincoln had not arrived at maturity
in 1865, and I say so now. His blood ran slowly—had low or
slow circulation and consequently a slow build-up. As he had a
slow build-up, so he had a slow development; he grew up like
the forest oak, tough, solid, knotty, gnarled, standing out with
power against the storm, and almost defying the lightning.
Hence I conclude that he had not arrived at his highest
development in 1865.... The convolutions of his brain were long;
they did not snap off quickly like a short, thick man's brain....
The enduring power of Mr. Lincoln's thought and brain was
wonderful. He could sit and think without food or rest longer
than any man I ever saw."
He goes into detail concerning Mr. Lincoln's bodily lethargy and its
effect on body and mind, the sluggishness of all his functions, and
affirms that this must be taken into account in any right estimate of
the man; but that steadily, and the more surely because slowly, his
mind and soul developed and became more and more dominant.
"His flesh looked dry and leathery, tough and everlasting; his
eyes were small and gray; head small and forehead receding;
but when this great man was moved by some great and good
feeling, by some idea of Liberty, or Justice, or Right, then he
seemed an inspired man. It was just then that Lincoln's nature
was beautiful, and in complete harmony with the laws of the
Great Eternal. I have seen him in this inspired condition, and
thought he was molded in the Spirit's best mold. Lincoln was a
great man, a good man, and a pure man; and beneath his
rough bodily exterior, Nature wove her fine network of nerve....
Lincoln was a gloomy man at one moment and a joyous man
the next; he was conscious that a terrible fate awaited him. He
said to me, 'I cannot help but believe that I shall meet with
some terrible end.' This idea seized him and made him gloomy.
At times his better nature would get the mastery of him, and he
would be happy till the shadow of his fate flitted before him. In
philosophy Lincoln was a fatalist.... In my poor opinion, Lincoln
had not arrived, when he was assassinated, at the meridian of
his intellectual power.... Were you to read his early speeches
thoroughly you would see his then coarse nature. He gradually
rose up, more spiritualistic. This is one of the reasons why I say
that Lincoln was not fully developed in mind at the last. When a
great Boston man said, 'Lincoln died at the right time,' he did
not know what he was talking about."
In these and like paragraphs Herndon testified to the mental and
spiritual evolution of Lincoln; and he was probably correct when he
opined that that evolution was still in process, and that Lincoln was,
up to the very hour of his death, a growing man in all that meant
most to America and the world.
The religion of Abraham Lincoln was part and parcel of his life; and
his life was an evolution whose successive stages can be measured
with reasonable certainty. Not only did his religious convictions
develop and broaden under the stimuli of Lincoln's constantly
broadening intellectual and spiritual environment, but they
broadened in the growth of his own personality.
There was an evolution in his apprehension of the ethical
implications of public office. The Lincoln who re-entered politics after
the repeal of the Missouri Compromise was a changed man from the
Lincoln who, with the other members of the "Long Nine," earned by
political log-rolling the severe but not wholly unmerited name
applied to them by one of Illinois' best governors, "spared
monuments of popular wrath." That Lincoln did not in this earlier
period commit any personally dishonorable act is not an argument
against the theory here advocated. He had, in his later political
career, a far higher ideal of political honor, a greatly nobler
conception of the dignity of public office—which he always sought—
as a field of popular service. His political career was an evolution,
and it developed nobler characteristics than that which characterized
his earlier political life.
Lincoln's emancipation policy was an evolution. The successive
stages of that policy were worthily set forth by Paul Selby in an
address before the Historical Society of Chicago.[64] There never was
a time when Abraham Lincoln did not believe slavery to be wrong,
but there was a time when he was not an Abolitionist. The moral
aspect of the slavery question grew in his mind and conscience till
he promised his God to free the slaves.
On Sunday evening, September 7, 1862, a public meeting was held
in Bryan Hall, Chicago, to urge upon the President the desire of
Christian people that he should free the slaves. A petition was
circulated, and was signed by all the Congregational and nearly all
the Methodist and Baptist ministers of that city, courteously
requesting the President to give the matter his earnest attention.
The petition was sent to Washington by the hand of Rev. William W.
Patton and Rev. John Dempster, who met the President by
appointment on Saturday afternoon, September 13, the interview
being arranged by Hon. Gideon Welles.
The story of that meeting has often been told in part, with undue
emphasis upon Mr. Lincoln's statement then made that if God had a
message for him on this subject He would be more likely to
communicate it directly to Mr. Lincoln than to others for him. The
latest book to misuse this incident is one just from the press in Great
Britain, the Short Life of Lincoln, by Hon. Ralph Shirley, who says:
"In regard to this great book, I have only to say it is the best
gift which God has ever given man. All the good from the
Saviour of the world is communicated to us through this
book."—Carpenter: Six Months in the White House, p. 199; also
Nicolay and Hay: Works of Lincoln, twelve volume edition, X,
217-18.
ebookgate.com