Files | |
file | eg_macros.c |
implementation of some macros. | |
file | eg_macros.h |
Code Location Utility: | |
this are utility macros to print information about where we are.
| |
#define | __EG_PRINTLOC2__ __EG_PRINTLOC2F__(stderr) |
#define | __EG_PRINTLOC2F__(F) fprintf(((F==0)?stderr:F),"in %s (%s:%d)\n",__func__,__FILE__,__LINE__) |
#define | __EG_PRINTLOC__ __EG_PRINTLOCF__(stderr) |
#define | __EG_PRINTLOCF__(F) fprintf(((F==0)?stderr:F),", in %s (%s:%d)\n",__func__,__FILE__,__LINE__) |
Algorithms Return Status | |
Here we define some general status for algorithms, the exact meaning should be sought in the actual algorithm definition, but the definitions here provide a first overview of their meaning. | |
#define | EG_ALGSTAT_ERROR 3 |
the algorithm stop because of some unforeseen error | |
#define | EG_ALGSTAT_NUMERROR 2 |
the algorithm stop because of some numerical problem | |
#define | EG_ALGSTAT_PARTIAL 1 |
the algorithm could only partially finish | |
#define | EG_ALGSTAT_SUCCESS 0 |
the algorithm finish successfully. | |
Mathematical Constants | |
Here we define some mathematical constants needed in some parts of the code that are of general use | |
#define | EG_M_PI 3.1415926535897932384626433832795029L |
definition of ![]() | |
External C-library functions: | |
Here we define some C-library functions that for some weird reason can't be found at compile time but are present at linking time | |
double | drand48 (void) |
int | finite (double) |
int | getopt (int, char *const *, const char *) |
long | lrand48 (void) |
long | random (void) |
void | srandom (unsigned int) |
char * | optarg |
Defines | |
#define | ADVCHECKRVAL(A, B) |
this macro test if a value is non zero, if it is it print where is it and return B. The idea is to use it to check return values of functions | |
#define | ADVTESTL(level, cond, rval,) |
This macro test a condition 'cond' when the debug level used at compile time is at least 'level'. If the condition is true, it print the message and return the 'rval' value. | |
#define | CHECKRVAL(A) |
this macro test if a value is non zero, if it is it print where is it and return 1. The idea is to use it to check return values of functions | |
#define | CHECKRVALG(A, B) |
this function, if the input is non zero, print a message of function, file and line and then goto the second parameter | |
#define | EGcontainerOf(ptr, type, member) |
given a pointer to a member of a structure, return the pointer to the head of the structure. (idea taken from Linux Kernel). | |
#define | EGoffsetOf(type, member) ((size_t) &((type *)0)->member) |
return the offset of a member inside a structure. | |
#define | EGosGetData(data, osN, type) (*((type*)(((char*)data)+osN))) |
retrieve the data of type 'type' in the structure 'data' that is located in the offset 'osN'. | |
#define | EGosSetData(data, osN, type, val) (EGosGetData(data,osN,type)=val) |
set the data of type 'type' in the structure 'data' that is located in the offset 'osN' to the value 'val'. | |
#define | EGRAND_MAX RAND_MAX |
Define the real rand_max value of (random). In linux machines is as RAND_MAX, but in SUN is 2^31-1. | |
#define | EXIT(A,) |
This macro is to print error messages and exit the program with code one from the current function, it also print the file and line where this happend. | |
#define | EXITL(L, A,) |
This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend, but the condition is looked only if the debug level is at least L. | |
#define | EXITRVAL(A) |
this macro test if a value is non zero, if it is it print where is it and exit 1. The idea is to use it to check return values of functions, and the calling function can't return a status, and then we are forced to exit. | |
#define | MESSAGE(A,) |
This macro print messages to the screen when the debug level is as big as the first parameter, if the debug level is zero we eliminate the code and reduce it to the empty instruction. | |
#define | MESSAGEF(A, F,) |
This macro print messages to the screen when the debug level is as big as the first parameter, if the debug level is zero we eliminate the code and reduce it to the empty instruction. | |
#define | nullCopy ((EGcopy_f)0) |
Define a null copy function. | |
#define | OUTPUT(A,) |
This macro print messages to the screen when the verbose level is as big as the first parameter, if the verbose level is zero we eliminate the code and reduce it to the empty instruction. | |
#define | PTRTEST(ptr, rval) |
this macro check if the value of a pointer is not bellow the first 64Kb, if so it return the given value | |
#define | TEST(A,) |
This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend. | |
#define | TESTERRNOIF(__value) |
, if a non-zero value is given as an argument, check the errno stored in the system, print the related message, and return the non-zero given parameter, otherwise, do nothing. | |
#define | TESTG(A, B,) |
This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend. | |
#define | TESTL(L, A,) |
This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend, but the condition is looked only if the debug level is at least L. | |
#define | typeof __typeof__ |
We define the GNU C extension typeof if necesary. | |
#define | WARNING(A,) |
This macro print messages to the screen when the condition A is true. | |
#define | WARNINGL(L, A,) |
This macro print messages to the screen when the condition A is true .if the debug level is one we don't print any warning message. if the debug level is zero we eliminate the code and reduce it to the empty instruction. | |
Typedefs | |
typedef void *(* | EGcopy_f )(void *p) |
Defione copy functions, these functions return copy of objects but with independent storage space, there are two versions, one that require a memory pool from where to look for memory, and another where we don't care about that.... the place from where the memory was asked for depend on the function, se the function definition for details. Note that if the is no more memory available the function should call exit(1). This is only intended as a readibility help. | |
Functions | |
void | EGlib_info (void) |
Display information about the library and the running process. |
|
Definition at line 151 of file eg_macros.h. |
|
Definition at line 150 of file eg_macros.h. |
|
Definition at line 149 of file eg_macros.h. |
|
Definition at line 148 of file eg_macros.h. |
|
Value: ({\ if(A){\ __EG_PRINTLOC2__;\ return B;}})
Definition at line 291 of file eg_macros.h. |
|
Value: ({\ if((DEBUG>=level)&&(cond)){\ fprintf(stderr,__VA_ARGS__);\ __EG_PRINTLOC__;\ return rval;}})
Definition at line 300 of file eg_macros.h. |
|
Value: ({\ if(A){\ __EG_PRINTLOC2__;\ return A;}})
Definition at line 310 of file eg_macros.h. |
|
Value: ({\ if(A){\ __EG_PRINTLOC2__;\ goto B;}})
Definition at line 330 of file eg_macros.h. |
|
the algorithm stop because of some unforeseen error
Definition at line 387 of file eg_macros.h. |
|
the algorithm stop because of some numerical problem
Definition at line 385 of file eg_macros.h. |
|
the algorithm could only partially finish
Definition at line 383 of file eg_macros.h. |
|
the algorithm finish successfully.
Definition at line 381 of file eg_macros.h. |
|
definition of
Definition at line 397 of file eg_macros.h. |
|
Value: ({\ typeof(((type *)0)->member) *const __EGcOf_ptr = (ptr);\ (type *)( (char*)__EGcOf_ptr - ((size_t) &((type *)0)->member));})
Definition at line 122 of file eg_macros.h. |
|
return the offset of a member inside a structure.
Definition at line 112 of file eg_macros.h. |
|
retrieve the data of type 'type' in the structure 'data' that is located in the offset 'osN'.
Definition at line 351 of file eg_macros.h. |
|
set the data of type 'type' in the structure 'data' that is located in the offset 'osN' to the value 'val'.
Definition at line 356 of file eg_macros.h. |
|
Define the real rand_max value of (random). In linux machines is as RAND_MAX, but in SUN is 2^31-1.
Definition at line 339 of file eg_macros.h. |
|
Value: ({if(A){\ fprintf(stderr,"EXIT: ");\ fprintf(stderr,__VA_ARGS__);\ __EG_PRINTLOC__;\ exit(1);}})
Definition at line 281 of file eg_macros.h. |
|
Value: ({\ if(L<=DEBUG){\ if(A){\ fprintf(stderr,__VA_ARGS__);\ __EG_PRINTLOC__;\ exit(1);}}})
Definition at line 160 of file eg_macros.h. |
|
Value: ({\ if(A){\ __EG_PRINTLOC2__;\ exit(1);}})
Definition at line 272 of file eg_macros.h. |
|
Value: ({\ if(A <= DEBUG ){\ fprintf(stderr,__VA_ARGS__);\ __EG_PRINTLOC__;}})
Definition at line 220 of file eg_macros.h. |
|
Value: ({\ if(A <= DEBUG ){\ fprintf(((F==0)?stderr:F),__VA_ARGS__);\ __EG_PRINTLOCF__(F);}})
Definition at line 211 of file eg_macros.h. |
|
Define a null copy function.
Definition at line 372 of file eg_macros.h. |
|
Value: ({\ if(A <= VERBOSE_LEVEL ){\ fprintf(stderr,__VA_ARGS__);}})
Definition at line 230 of file eg_macros.h. |
|
Value: {\ if(ptr) ADVTESTL(0,((size_t)(ptr)) < (1U<<16),rval, \ "%s=%p is not a valid pointer",\ #ptr, (void*)(ptr));}
Definition at line 182 of file eg_macros.h. |
|
Value: ({\ if(A){\ fprintf(stderr,__VA_ARGS__);\ __EG_PRINTLOC__;\ return 1;}})
Definition at line 201 of file eg_macros.h. |
|
Value: do{\ if(__value){\ const int __EGserrno = errno;\ fprintf(stderr,"failed with errno %d, %s\n",__EGserrno, strerror(__EGserrno));\ __EG_PRINTLOC2__;\ return __value;}}while(0)
Definition at line 321 of file eg_macros.h. |
|
Value: ({\ if(A){\ fprintf(stderr,__VA_ARGS__);\ __EG_PRINTLOC__;\ goto B;}})
Definition at line 191 of file eg_macros.h. |
|
Value: ({\ if(L<=DEBUG){\ if(A){\ fprintf(stderr,__VA_ARGS__);\ __EG_PRINTLOC__;\ return 1;}}})
Definition at line 172 of file eg_macros.h. |
|
We define the GNU C extension typeof if necesary.
Definition at line 102 of file eg_macros.h. |
|
Value: ({if(A){\ fprintf(stderr,"WARNING: ");\ fprintf(stderr,__VA_ARGS__);\ __EG_PRINTLOC__;}})
Definition at line 262 of file eg_macros.h. |
|
Value: ({\ if((A)&&(DEBUG>=L)){\ fprintf(stderr,"WARNING: ");\ fprintf(stderr,__VA_ARGS__);\ __EG_PRINTLOC__;}})
Definition at line 242 of file eg_macros.h. |
|
Defione copy functions, these functions return copy of objects but with independent storage space, there are two versions, one that require a memory pool from where to look for memory, and another where we don't care about that.... the place from where the memory was asked for depend on the function, se the function definition for details. Note that if the is no more memory available the function should call exit(1). This is only intended as a readibility help.
Definition at line 368 of file eg_macros.h. |
|
|
|
Display information about the library and the running process.
Definition at line 35 of file eg_macros.c. |
|
|
|
|
|
|
|
|
|
|
|
|