Le 04/06/2014 21:35, Malcolm McLean a écrit :
nobody in their right mind would prefer this interface [pass an error
flag in as a pointer] when the function returns nothing.
If you've got a convention that error shall always be a pointer and
shall always be the last parameter, it's best to stick to it.
The convention has some value when functions naturally return a
result, in some libraries results are returned through pointers,
purely to preserve the convention that the return type shall be
the error status.
In the containers library I used another convention. Error return (an
integer mostly) in the result, and parameters by pointers.
Functions that return pointers are also boolean: either it is a valid
pointer or NULL. Obviously when ANY error happens, the standard
callbacks are called, before any other action.
The library comes with default callbacks that put something in stderr
and go on.
The library user can change this as he/she wants by changing the
callbacks and putting other functions.
So:
int errorCode = Interface.functionXXX(Object *,...);
Positive: OK
Zero: OK with warnings
Negative: hard error
if (List.Append(memberslist,newSubscriptions ) >= 0)
// OK;
else return NULL;
To do:
Extensible. You should be able to add your own error types to the table.
I think that a utility could inspect the executable between two UUIDs,
modifying parameters in the style:
What do you want to do
when there is no more memory?
When a bad pointer is discovered?
Array bounds exceeded?
Other internal inconsistencies?
Do you want to log all errors?
If yes where (path)?
Binary layout would be:
static uuid start = { };
/* Modifiable parameters */
size_t size;
char strict=0; // Go on by default
.... // Other parameters
statuc uuid end = { };
The size data field means the number of bytes to skip to find the end uuid.
A simple utility scans the executable for the start uuid, reads the size
parameter, skips that number of bytes and verifies that the end uuid is
also there.
Now, the default callback of the no memory error would look at the value
of strict. If non zero it will exit the program. Other callbacks may or
may not follow that convention.
This gives great flexibility to classify errors. For instance some
memory-hog program crashes but the main programis not affected, it is an
optional functionality, available only when more memory is there.