+#define LIMIT_TYPED(n,t) \
+ (t)(((n) > MAX_OF_TYPE(t)) \
+ ? MAX_OF_TYPE(t) \
+ : ((n) < -MAX_OF_TYPE(t)) \
+ ? -MAX_OF_TYPE(t) \
+ : (n))
+
+#define limit_COLOR(n) LIMIT_TYPED(n,NCURSES_COLOR_T)
+#define limit_PAIRS(n) LIMIT_TYPED(n,NCURSES_PAIRS_T)
+
+#define MAX_XCURSES_PAIR MAX_OF_TYPE(NCURSES_PAIRS_T)
+
+#if NCURSES_EXT_COLORS
+#define OPTIONAL_PAIR GCC_UNUSED
+#define get_extended_pair(opts, color_pair) \
+ if ((opts) != NULL) { \
+ *(int*)(opts) = color_pair; \
+ }
+#define set_extended_pair(opts, color_pair) \
+ if ((opts) != NULL) { \
+ color_pair = *(const int*)(opts); \
+ }
+#else
+#define OPTIONAL_PAIR /* nothing */
+#define get_extended_pair(opts, color_pair) /* nothing */
+#define set_extended_pair(opts, color_pair) \
+ if ((opts) != NULL) { \
+ color_pair = -1; \
+ }
+#endif