cb22561995-10-11Fredrik Hübinette (Hubbe) /*\
06983f1996-09-22Fredrik Hübinette (Hubbe) ||| This file a part of Pike, and is copyright by Fredrik Hubinette ||| Pike is distributed as GPL (General Public License)
cb22561995-10-11Fredrik Hübinette (Hubbe) ||| See the files COPYING and DISCLAIMER for more information. \*/
24ddc71998-03-28Henrik Grubbström (Grubba)  /*
2e104a1998-05-06Henrik Grubbström (Grubba)  * $Id: pike_macros.h,v 1.8 1998/05/05 22:01:41 grubba Exp $
24ddc71998-03-28Henrik Grubbström (Grubba)  */
5267b71995-08-09Fredrik Hübinette (Hubbe) #ifndef MACROS_H #define MACROS_H
bdfb861997-12-22Fredrik Hübinette (Hubbe) #include <global.h> #ifdef HAVE_SYS_PARAM_H
5267b71995-08-09Fredrik Hübinette (Hubbe) #include <sys/param.h>
bdfb861997-12-22Fredrik Hübinette (Hubbe) #endif
9aa6fa1997-05-19Fredrik Hübinette (Hubbe) #include "pike_memory.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) 
d4828c1997-07-17Fredrik Hübinette (Hubbe) #define OFFSETOF(str_type, field) ((long)& (((struct str_type *)0)->field))
5267b71995-08-09Fredrik Hübinette (Hubbe) #define BASEOF(ptr, str_type, field) \ ((struct str_type *)((char*)ptr - (char*)& (((struct str_type *)0)->field))) #define NELEM(a) (sizeof (a) / sizeof ((a)[0])) #define ALLOC_STRUCT(X) ( (struct X *)xalloc(sizeof(struct X)) ) #define MINIMUM(X,Y) ((X)<(Y)?(X):(Y)) #define MAXIMUM(X,Y) ((X)>(Y)?(X):(Y))
b432bb1996-10-29Per Hedbor 
4649141997-09-27Henrik Grubbström (Grubba) #define is8bitalnum(X) ("0000000000000000" \
2e104a1998-05-06Henrik Grubbström (Grubba)  "0000000000000000" \
4649141997-09-27Henrik Grubbström (Grubba)  "0000000000000000" \ "1111111111000000" \ "0111111111111111" \ "1111111111100001" \ "0111111111111111" \ "1111111111100000" \ "0000000000000000" \ "0000000000000000" \ "1011110101100010" \ "1011011001101110" \ "1111111111111111" \ "1111111011111111" \ "1111111111111111" \ "1111111011111111"[((unsigned)(X))&0xff] == '1')
b432bb1996-10-29Per Hedbor  #define isidchar(X) is8bitalnum(X)
5c8e891995-10-29Fredrik Hübinette (Hubbe) 
f90e541995-08-17Fredrik Hübinette (Hubbe) #define ALIGN_BOUND sizeof(char *)
5267b71995-08-09Fredrik Hübinette (Hubbe) 
1994981998-04-07Fredrik Hübinette (Hubbe) #ifdef __GNUC__ #define ALIGNOF(X) __alignof__(X) #define HAVE_ALIGNOF #else #define ALIGNOF(X) (sizeof(X)>ALIGN_BOUND?ALIGN_BOUND:( 1<<my_log2(sizeof(X)))) #endif #define DO_ALIGN(X,Y) (((long)(X)+((Y)-1)) & -(Y)) #define MY_ALIGN(X) DO_ALIGN((X),ALIGN_BOUND) #define SMART_ALIGN(X,Y) DO_ALIGN((X),(Y)>ALIGN_BOUND? (((Y)-1) & ~(Y)) :ALIGN_BOUND)
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif