/usr/include
) can also be very
informative.
<assert.h>
void assert(int )
. If the
value in the argument is non-zero, nothing exciting happens. The
program continues on. If the argument evaluates to zero, the
program dies after printing a message on the standard error file
(usually the screen).
The ONLY reasonable use for this function is in debugging. You
sprinkle assert()
s throughout the program, giving
as the argument an expression that you think should be true at
that point in the program. When the program runs, it evaluates
your assertion (expression). If you were wrong, the program
tells you where it's at, dies, and you get to figure out why
your logic was wrong at that point. A very useful
function.
But wait, there's more! If you #define NDEBUG
before #include <assert.h>
all of your
assert()
s are cheerfully ignored. So you can
enable or disable all of your debugging checking by changing a
single line.
<ctype.h>
int
) and return a non-zero or zero value according to
whether the character meets or does not meet the given criterion.
These functions are usually implemented as lookup tables optimized
for each specific architecture, so calling isupper(c)
is much faster than if(c >= 'A' && c <='Z') ...
.
isalnum(c)
isalpha(c)
iscntrl(c)
isdigit(c)
isgraph(c)
islower(c)
isprint(c)
ispunct(c)
isspace(c)
isupper(c)
isxdigit(c)
int tolower(int c)
int toupper(int c)
<limits.h>
unsigned
int
is 65535 on a PC running DOS, and 4294967295 on a PC
running Unix. The maxmimum value of an unsigned long
int
is 4294967295 on a Pentium class machine running Unix
and 18446744073709551615 on a DEC Alpha machine running Unix.
Many programs break down when ported to different architectures because they make assumptions about the capacity of fundamental types. Using this header file helps eliminate that problem.
These values are all #define
d in
<limits.h>
SCHAR_MIN
& SCHAR_MAX
UCHAR_MAX
CHAR_MIN
& CHAR_MAX
SHRT_MIN
& SHRT_MAX
USRHT_MAX
INT_MIN
& INT_MAX
UINT_MAX
LONG_MIN
& LONG_MAX
ULONG_MAX
<float.h>
<limits.h>
except for
floating point types instead of integers. These
#define
d values can vary according to architecture.
Very important for portability of numeric processing programs.
FLT_MIN
& FLT_MAX
float
s.
DBL_MIN
& DBL_MAX
double
s.
FLT_EPSILON
& DBL_EPSILON
<stdio.h>
<stdlib.h>
double atof(char *)
, int atoi(char
*)
, and long atol(char *)
double strtod()
, long strtol()
,
and strtoul()
atof()
and friends. The integer versions are
able to convert numbers of different bases. Each of the
str... functions also returns a pointer to the location in the
string where it stopped the conversion.
int rand(void)
RAND_MAX
which is a symbolic
constant also defined in this file.
void srand(unsigned int)
void * malloc(int)
malloc()
returns NULL
.
void * calloc(int n_obj, int size)
n_obj
objects, each containing size
bytes. Also
initializes the allocated memory to all zeros. Much faster
than using malloc()
and then writing your own
loop to clear the memory. If you have to initialize the
memory to some complex value, calloc()
is a waste
of time.
void * realloc(void * p, int size)