cslib.h
Types | |
This type defines the space of Boolean data using the constants false and true . | |
This type is defined to be identical with char * . | |
This function type represents an arbitrary procedure that can be passed to an abstraction and then called back from the implementation. | |
Functions | |
Allocates a block of memory of the given size. | |
Frees the memory associated with ptr , which must have been allocated using getBlock , newBlock , or newArray . | |
Returns a string indicating the type of the block. | |
Sets the data field inside the block to the specified value. | |
Returns the data field inside the block. | |
Generates an error string, expanding % constructions appearing in the error message string just as printf does. |
false
and true
.
typedef char *string;
char *
.
typedef void proc(*proc)();
void *getBlock(size_t nbytes);
getBlock
generates an error.
Usage:
ptr = getBlock(nbytes);
void freeBlock(void *ptr);
ptr
, which must have
been allocated using getBlock
, newBlock
, or
newArray
. If the block appears to be in static memory
or allocated by malloc
, the call to freeBlock
has no effect.
Usage:
freeBlock(ptr);
string getBlockType(void *ptr);
newBlock
macro, the string is the type
argument. If the block is created using newArray
, the
string consists of the base type followed by the string "[]"
.
In all other cases, the type is returned as "?"
. This
string is constant and should not be freed.
Usage:
type = getBlockType(ptr);
void setBlockData(void *ptr, void *value);
Usage:
setBlockData(ptr, value);
void *getBlockData(void *ptr);
Usage:
value = getBlockData(ptr);
void error(string msg, ...);
%
constructions
appearing in the error message string just as printf
does.
The behavior depends on whether the call is compiled in C or C++.
In C, calling error
first checks to see if there is a
handler for ErrorException
. If so, calling
error
throws an ErrorException
exception with the expanded error string as argument. If
there is no ErrorException
handler, the program
prints the message to the standard error channel and exits
with a status code indicating failure (as given by the
constant ERROR_EXIT_STATUS
).
In C++, calling error
throws an exception with the
expanded error string (defined as a C++ string) as its value.
Usage:
error(msg, . . .);