c.texi: many small fixes and cleanups.

This commit is contained in:
Richard Stallman 2023-07-27 14:39:56 -04:00
parent 3974c46326
commit 26f5cf9300
1 changed files with 34 additions and 27 deletions

61
c.texi
View File

@ -84,9 +84,9 @@ Cover art by J. Random Artist
@end iftex @end iftex
This manual explains the C language for use with the GNU Compiler This manual explains the C language for use with the GNU Compiler
Collection (GCC) on the GNU/Linux system and other systems. We refer Collection (GCC) on the GNU/Linux operating system and other systems.
to this dialect as GNU C. If you already know C, you can use this as We refer to this dialect as GNU C. If you already know C, you can use
a reference manual. this as a reference manual.
If you understand basic concepts of programming but know nothing about If you understand basic concepts of programming but know nothing about
C, you can read this manual sequentially from the beginning to learn C, you can read this manual sequentially from the beginning to learn
@ -95,8 +95,8 @@ the C language.
If you are a beginner in programming, we recommend you first learn a If you are a beginner in programming, we recommend you first learn a
language with automatic garbage collection and no explicit pointers, language with automatic garbage collection and no explicit pointers,
rather than starting with C@. Good choices include Lisp, Scheme, rather than starting with C@. Good choices include Lisp, Scheme,
Python and Java. C's explicit pointers mean that programmers must be Python and Java. Because of C's explicit pointers, programmers must be
careful to avoid certain kinds of errors. careful to avoid certain kinds of errors in memory usage.
C is a venerable language; it was first used in 1973. The GNU C C is a venerable language; it was first used in 1973. The GNU C
Compiler, which was subsequently extended into the GNU Compiler Compiler, which was subsequently extended into the GNU Compiler
@ -125,15 +125,15 @@ However, standards and other dialects are secondary topics for this
manual. For simplicity's sake, we keep those notes short, unless it manual. For simplicity's sake, we keep those notes short, unless it
is vital to say more. is vital to say more.
Likewise, we hardly mention C@t{++} or other languages that the GNU
Compiler Collection supports. We hope this manual will serve as a
base for writing manuals for those languages, but languages so
different can't share one common manual.
Some aspects of the meaning of C programs depend on the target Some aspects of the meaning of C programs depend on the target
platform: which computer, and which operating system, the compiled platform: which computer, and which operating system, the compiled
code will run on. Where this is the case, we say so. code will run on. Where this is the case, we say so.
We hardly mention C@t{++} or other languages that the GNU
Compiler Collection supports. We hope this manual will serve as a
base for writing manuals for those languages, but languages so
different can't share one common manual.
The C language provides no built-in facilities for performing such The C language provides no built-in facilities for performing such
common operations as input/output, memory management, string common operations as input/output, memory management, string
manipulation, and the like. Instead, these facilities are provided by manipulation, and the like. Instead, these facilities are provided by
@ -141,13 +141,13 @@ functions defined in the standard library, which is automatically
available in every C program. @xref{Top, The GNU C Library, , libc, available in every C program. @xref{Top, The GNU C Library, , libc,
The GNU C Library Reference Manual}. The GNU C Library Reference Manual}.
GNU/Linux systems use the GNU C Library to do this job. It is itself Most GNU/Linux systems use the GNU C Library to provide those facilities.
a C program, so once you know C you can read its source code and see It is itself written in C, so once you know C you can read its source
how its library functions do their jobs. Some fraction of the code and see how its library functions do their jobs. Some fraction
functions are implemented as @dfn{system calls}, which means they of the functions are implemented as @dfn{system calls}, which means
contain a special instruction that asks the system kernel (Linux) to they contain a special instruction that asks the system kernel (Linux)
do a specific task. To understand how those are implemented, you'd to do a specific task. To understand how those are implemented, you'd
need to read Linux source code instead. Whether a library function is need to read Linux source code. Whether a library function is
a system call is an internal implementation detail that makes no a system call is an internal implementation detail that makes no
difference for how to call the function. difference for how to call the function.
@ -5032,7 +5032,7 @@ Remember, to understand what type a designator stands for, imagine the
corresponding variable declaration with a variable name in it, and corresponding variable declaration with a variable name in it, and
figure out what type that variable would have. Thus, the type figure out what type that variable would have. Thus, the type
designator @code{double (*)[5]} corresponds to the variable declaration designator @code{double (*)[5]} corresponds to the variable declaration
@code{double (*@var{variable})[5]}. That deciares a pointer variable @code{double (*@var{variable})[5]}. That declares a pointer variable
which, when dereferenced, gives an array of 5 @code{double}s. which, when dereferenced, gives an array of 5 @code{double}s.
So the type designator means, ``pointer to an array of 5 @code{double}s.'' So the type designator means, ``pointer to an array of 5 @code{double}s.''
@ -5212,7 +5212,8 @@ type, if the left operand has a pointer type; for instance,
Passing an argument of type @code{void *} for a parameter that has a Passing an argument of type @code{void *} for a parameter that has a
pointer type also converts. For example, supposing the function pointer type also converts. For example, supposing the function
@code{hack} is declared to require type @code{float *} for its @code{hack} is declared to require type @code{float *} for its
argument, this will convert the null pointer to that type. parameter, this call to @code{hack} will convert the argument to that
type.
@example @example
/* @r{Declare @code{hack} that way.} /* @r{Declare @code{hack} that way.}
@ -6682,7 +6683,7 @@ This specifies @code{x + y} for field @code{a},
the character @samp{a} for field @code{b}'s element 0, the character @samp{a} for field @code{b}'s element 0,
and the null character for field @code{b}'s element 1. and the null character for field @code{b}'s element 1.
The parentheses around that constructor are to necessary, but we The parentheses around that constructor are not necessary, but we
recommend writing them to make the nesting of the containing recommend writing them to make the nesting of the containing
expression clearer. expression clearer.
@ -7253,14 +7254,20 @@ for accessing elements of the array, but it matters for some other
things. For instance, @code{sizeof} is not allowed on an incomplete things. For instance, @code{sizeof} is not allowed on an incomplete
type. type.
With multidimensional arrays, only the first dimension can be omitted: With multidimensional arrays, only the first dimension can be omitted.
For example, suppose we want to represent the positions of pieces on a
chessboard which has the usual 8 files (columns), but more (or fewer)
ranks (rows) than the usual 8. This declaration could hold a pointer
to a two-dimensional array that can hold that data. Each element of
the array holds one row.
@example @example
extern struct chesspiece *funnyboard foo[][8]; struct chesspiece *funnyboard[][8];
@end example @end example
In other words, the code doesn't have to say how many rows there are, Since it is just a pointer to the start of an array, its type can be
but it must state how big each row is. incomplete, but it must state how big each array element is---the
number of elements in each row.
@node Limitations of C Arrays @node Limitations of C Arrays
@section Limitations of C Arrays @section Limitations of C Arrays
@ -11275,7 +11282,7 @@ another.
@cindex thunks @cindex thunks
A @dfn{nested function} is a function defined inside another function. A @dfn{nested function} is a function defined inside another function.
(The ability to do this indispensable for automatic translation of (The ability to do this is indispensable for automatic translation of
certain programming languages into C.) The nested function's name is certain programming languages into C.) The nested function's name is
local to the block where it is defined. For example, here we define a local to the block where it is defined. For example, here we define a
nested function named @code{square}, then call it twice: nested function named @code{square}, then call it twice:
@ -11991,8 +11998,8 @@ Each definition or declaration of an identifier is visible
in certain parts of the program, which is typically less than the whole in certain parts of the program, which is typically less than the whole
of the program. The parts where it is visible are called its @dfn{scope}. of the program. The parts where it is visible are called its @dfn{scope}.
Normally, declarations made at the top-level in the source -- that is, Normally, declarations made at the top-level in the source---that is,
not within any blocks and function definitions -- are visible for the not within any blocks and function definitions---are visible for the
entire contents of the source file after that point. This is called entire contents of the source file after that point. This is called
@dfn{file scope} (@pxref{File-Scope Variables}). @dfn{file scope} (@pxref{File-Scope Variables}).