General Macros


Detailed Description

global macros and types for EGlib

Version:
0.9.2
History:


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.
Note:
For some reason __func__ don't work correctly for sun's cc in inline functions, so we don't use in SUN architecture


#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 $\pi$ as a constant, suitable for quad-IEEE operations.

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.


Define Documentation

#define __EG_PRINTLOC2__   __EG_PRINTLOC2F__(stderr)
 

Definition at line 151 of file eg_macros.h.

#define __EG_PRINTLOC2F__  )     fprintf(((F==0)?stderr:F),"in %s (%s:%d)\n",__func__,__FILE__,__LINE__)
 

Definition at line 150 of file eg_macros.h.

#define __EG_PRINTLOC__   __EG_PRINTLOCF__(stderr)
 

Definition at line 149 of file eg_macros.h.

#define __EG_PRINTLOCF__  )     fprintf(((F==0)?stderr:F),", in %s (%s:%d)\n",__func__,__FILE__,__LINE__)
 

Definition at line 148 of file eg_macros.h.

#define ADVCHECKRVAL A,
 ) 
 

Value:

({\
  if(A){\
    __EG_PRINTLOC2__;\
    return 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

Definition at line 291 of file eg_macros.h.

#define ADVTESTL level,
cond,
rval   ) 
 

Value:

({\
  if((DEBUG>=level)&&(cond)){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    return 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.

Definition at line 300 of file eg_macros.h.

#define CHECKRVAL  ) 
 

Value:

({\
  if(A){\
    __EG_PRINTLOC2__;\
    return 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

Definition at line 310 of file eg_macros.h.

#define CHECKRVALG A,
 ) 
 

Value:

({\
  if(A){\
    __EG_PRINTLOC2__;\
    goto B;}})
this function, if the input is non zero, print a message of function, file and line and then goto the second parameter

Definition at line 330 of file eg_macros.h.

#define EG_ALGSTAT_ERROR   3
 

the algorithm stop because of some unforeseen error

Definition at line 387 of file eg_macros.h.

#define EG_ALGSTAT_NUMERROR   2
 

the algorithm stop because of some numerical problem

Definition at line 385 of file eg_macros.h.

#define EG_ALGSTAT_PARTIAL   1
 

the algorithm could only partially finish

Definition at line 383 of file eg_macros.h.

#define EG_ALGSTAT_SUCCESS   0
 

the algorithm finish successfully.

Definition at line 381 of file eg_macros.h.

#define EG_M_PI   3.1415926535897932384626433832795029L
 

definition of $\pi$ as a constant, suitable for quad-IEEE operations.

Definition at line 397 of file eg_macros.h.

#define EGcontainerOf ptr,
type,
member   ) 
 

Value:

({\
  typeof(((type *)0)->member) *const __EGcOf_ptr = (ptr);\
  (type *)( (char*)__EGcOf_ptr - ((size_t) &((type *)0)->member));})
given a pointer to a member of a structure, return the pointer to the head of the structure. (idea taken from Linux Kernel).

Parameters:
ptr pointer to the member of the containing structure.
type name type of the containing structure.
member name of the given member in the containing structure.
Returns:
pointer to the containing structure.

Definition at line 122 of file eg_macros.h.

#define EGoffsetOf type,
member   )     ((size_t) &((type *)0)->member)
 

return the offset of a member inside a structure.

Parameters:
type the type of the containing structure.
member the name of the member that we are interested in compute the offset.
Returns:
the number of bytes between the member and the beginning of the structure.

Definition at line 112 of file eg_macros.h.

#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'.

Definition at line 351 of file eg_macros.h.

#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'.

Definition at line 356 of file eg_macros.h.

#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.

Definition at line 339 of file eg_macros.h.

#define EXIT  ) 
 

Value:

({if(A){\
    fprintf(stderr,"EXIT: ");\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    exit(1);}})
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.

Definition at line 281 of file eg_macros.h.

#define EXITL L,
 ) 
 

Value:

({\
  if(L<=DEBUG){\
  if(A){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    exit(1);}}})
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.

Definition at line 160 of file eg_macros.h.

#define EXITRVAL  ) 
 

Value:

({\
  if(A){\
    __EG_PRINTLOC2__;\
    exit(1);}})
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.

Definition at line 272 of file eg_macros.h.

#define MESSAGE  ) 
 

Value:

({\
  if(A <= DEBUG ){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;}})
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.

Definition at line 220 of file eg_macros.h.

#define MESSAGEF A,
 ) 
 

Value:

({\
  if(A <= DEBUG ){\
    fprintf(((F==0)?stderr:F),__VA_ARGS__);\
    __EG_PRINTLOCF__(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.

Definition at line 211 of file eg_macros.h.

#define nullCopy   ((EGcopy_f)0)
 

Define a null copy function.

Definition at line 372 of file eg_macros.h.

#define OUTPUT  ) 
 

Value:

({\
  if(A <= VERBOSE_LEVEL ){\
    fprintf(stderr,__VA_ARGS__);}})
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.

Definition at line 230 of file eg_macros.h.

#define PTRTEST ptr,
rval   ) 
 

Value:

{\
  if(ptr) ADVTESTL(0,((size_t)(ptr)) < (1U<<16),rval, \
                 "%s=%p is not a valid pointer",\
                  #ptr, (void*)(ptr));}
this macro check if the value of a pointer is not bellow the first 64Kb, if so it return the given value

Definition at line 182 of file eg_macros.h.

#define TEST  ) 
 

Value:

({\
  if(A){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    return 1;}})
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.

Definition at line 201 of file eg_macros.h.

#define TESTERRNOIF __value   ) 
 

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)
, 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.

Parameters:
__value if non-zero check systems errors, and return this value

Definition at line 321 of file eg_macros.h.

#define TESTG A,
 ) 
 

Value:

({\
  if(A){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    goto 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.

Definition at line 191 of file eg_macros.h.

#define TESTL L,
 ) 
 

Value:

({\
  if(L<=DEBUG){\
  if(A){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    return 1;}}})
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.

Definition at line 172 of file eg_macros.h.

#define typeof   __typeof__
 

We define the GNU C extension typeof if necesary.

Definition at line 102 of file eg_macros.h.

#define WARNING  ) 
 

Value:

({if(A){\
    fprintf(stderr,"WARNING: ");\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;}})
This macro print messages to the screen when the condition A is true.

Definition at line 262 of file eg_macros.h.

#define WARNINGL L,
 ) 
 

Value:

({\
  if((A)&&(DEBUG>=L)){\
    fprintf(stderr,"WARNING: ");\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;}})
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.

Definition at line 242 of file eg_macros.h.


Typedef Documentation

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.

Definition at line 368 of file eg_macros.h.


Function Documentation

double drand48 void   ) 
 

void EGlib_info void   ) 
 

Display information about the library and the running process.

Definition at line 35 of file eg_macros.c.

int finite double   ) 
 

int getopt int  ,
char *const *  ,
const char * 
 

long lrand48 void   ) 
 

long random void   ) 
 

void srandom unsigned  int  ) 
 


Variable Documentation

char* optarg
 


Generated on Wed Nov 21 09:38:35 2007 for MTgomory by  doxygen 1.4.6