]>
git.saurik.com Git - apt.git/blob - apt-pkg/contrib/macros.h
1 // -*- mode: cpp; mode: fold -*-
3 /* ######################################################################
5 Macros Header - Various useful macro definitions
7 This source is placed in the Public Domain, do with it what you will
8 It was originally written by Brian C. White.
10 ##################################################################### */
16 // MIN_VAL(SINT16) will return -0x8000 and MAX_VAL(SINT16) = 0x7FFF
17 #define MIN_VAL(t) (((t)(-1) > 0) ? (t)( 0) : (t)(((1L<<(sizeof(t)*8-1)) )))
18 #define MAX_VAL(t) (((t)(-1) > 0) ? (t)(-1) : (t)(((1L<<(sizeof(t)*8-1))-1)))
22 #if defined(__HIGHC__)
23 #define MIN(x,y) _min(x,y)
24 #define MAX(x,y) _max(x,y)
27 // GNU C++ has a min/max operator <coolio>
29 #define MIN(A,B) ((A) <? (B))
30 #define MAX(A,B) ((A) >? (B))
33 /* Templates tend to mess up existing code that uses min/max because of the
34 strict matching requirements */
36 #define MIN(A,B) ((A) < (B)?(A):(B))
37 #define MAX(A,B) ((A) > (B)?(A):(B))
41 /* Bound functions, bound will return the value b within the limits a-c
42 bounv will change b so that it is within the limits of a-c. */
43 #define _bound(a,b,c) MIN(c,MAX(b,a))
44 #define _boundv(a,b,c) b = _bound(a,b,c)
45 #define ABS(a) (((a) < (0)) ?-(a) : (a))
47 /* Usefull count macro, use on an array of things and it will return the
48 number of items in the array */
49 #define _count(a) (sizeof(a)/sizeof(a[0]))
52 #define FLAG(f) (1L << (f))
53 #define SETFLAG(v,f) ((v) |= FLAG(f))
54 #define CLRFLAG(v,f) ((v) &=~FLAG(f))
55 #define CHKFLAG(v,f) ((v) & FLAG(f) ? true : false)
57 // some nice optional GNUC features
59 #define __must_check __attribute__ ((warn_unused_result))
60 #define __deprecated __attribute__ ((deprecated))
61 /* likely() and unlikely() can be used to mark boolean expressions
62 as (not) likely true which will help the compiler to optimise */
63 #define likely(x) __builtin_expect (!!(x), 1)
64 #define unlikely(x) __builtin_expect (!!(x), 0)
66 #define __must_check /* no warn_unused_result */
67 #define __deprecated /* no deprecated */
69 #define unlikely(x) (x)
72 // cold functions are unlikely() to be called
73 #if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4
74 #define __cold __attribute__ ((__cold__))
76 #define __cold /* no cold marker */
80 // Methods have a hidden this parameter that is visible to this attribute
81 #define __like_printf_1 __attribute__ ((format (printf, 2, 3)))
82 #define __like_printf_2 __attribute__ ((format (printf, 3, 4)))
84 #define __like_printf_1
85 #define __like_printf_2