btcs

bitcoin script parser/evaluator/compiler/decompiler
git clone git://jb55.com/btcs
Log | Files | Refs | README | LICENSE

compiler.h (1617B)


      1 
      2 #ifndef COMPILER_H
      3 #define COMPILER_H
      4 
      5 #include <stdbool.h>
      6 #include <stdlib.h>
      7 #include <string.h>
      8 
      9 bool alignment_ok(const void *p, size_t n);
     10 
     11 #define UNUSED __attribute__((__unused__))
     12 
     13 /**
     14  * BUILD_ASSERT - assert a build-time dependency.
     15  * @cond: the compile-time condition which must be true.
     16  *
     17  * Your compile will fail if the condition isn't true, or can't be evaluated
     18  * by the compiler.  This can only be used within a function.
     19  *
     20  * Example:
     21  *	#include <stddef.h>
     22  *	...
     23  *	static char *foo_to_char(struct foo *foo)
     24  *	{
     25  *		// This code needs string to be at start of foo.
     26  *		BUILD_ASSERT(offsetof(struct foo, string) == 0);
     27  *		return (char *)foo;
     28  *	}
     29  */
     30 #define BUILD_ASSERT(cond) \
     31 	do { (void) sizeof(char [1 - 2*!(cond)]); } while(0)
     32 
     33 /**
     34  * BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression.
     35  * @cond: the compile-time condition which must be true.
     36  *
     37  * Your compile will fail if the condition isn't true, or can't be evaluated
     38  * by the compiler.  This can be used in an expression: its value is "0".
     39  *
     40  * Example:
     41  *	#define foo_to_char(foo)					\
     42  *		 ((char *)(foo)						\
     43  *		  + BUILD_ASSERT_OR_ZERO(offsetof(struct foo, string) == 0))
     44  */
     45 #define BUILD_ASSERT_OR_ZERO(cond) \
     46 	(sizeof(char [1 - 2*!(cond)]) - 1)
     47 
     48 #define memclear(mem, size) memset(mem, 0, size)
     49 #define memclear_2(m1, s1, m2, s2) { memclear(m1, s1); memclear(m2, s2); }
     50 #define memclear_3(m1, s1, m2, s2, m3, s3) { memclear(m1, s1); memclear(m2, s2); memclear(m3, s3); }
     51 #define wally_clear memclear
     52 #define wally_clear_2 memclear_2
     53 #define wally_clear_3 memclear_3
     54 
     55 #endif /* COMPILER_H */