summaryrefslogtreecommitdiffstats
path: root/sys/sys/cdefs.h
diff options
context:
space:
mode:
authorasomers <asomers@FreeBSD.org>2016-11-22 20:28:17 +0000
committerasomers <asomers@FreeBSD.org>2016-11-22 20:28:17 +0000
commit88e93daae771bcd26c329f87f9f443c02e47c7e4 (patch)
treee6721be614ef89478cfcbe059422f36ce59a3371 /sys/sys/cdefs.h
parent25a075724c584e1686b323f7a28f493e9d4b2c96 (diff)
downloadFreeBSD-src-88e93daae771bcd26c329f87f9f443c02e47c7e4.zip
FreeBSD-src-88e93daae771bcd26c329f87f9f443c02e47c7e4.tar.gz
MFC r307584
Fix C++ includability of crypto headers with static array sizes C99 allows array function parameters to use the static keyword for their sizes. This tells the compiler that the parameter will have at least the specified size, and calling code will fail to compile if that guarantee is not met. However, this syntax is not legal in C++. This commit reverts r300824, which worked around the problem for sys/sys/md5.h only, and introduces a new macro: min_size(). min_size(x) can be used in headers as a static array size, but will still compile in C++ mode.
Diffstat (limited to 'sys/sys/cdefs.h')
-rw-r--r--sys/sys/cdefs.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
index 89516cf..dd18784 100644
--- a/sys/sys/cdefs.h
+++ b/sys/sys/cdefs.h
@@ -341,6 +341,20 @@
__builtin_types_compatible_p(__typeof(expr), t), yes, no)
#endif
+/*
+ * C99 Static array indices in function parameter declarations. Syntax such as:
+ * void bar(int myArray[static 10]);
+ * is allowed in C99 but not in C++. Define __min_size appropriately so
+ * headers using it can be compiled in either language. Use like this:
+ * void bar(int myArray[__min_size(10)]);
+ */
+#if !defined(__cplusplus) && \
+ (!defined(__STDC_VERSION) || (__STDC_VERSION__ >= 199901))
+#define __min_size(x) static (x)
+#else
+#define __min_size(x) (x)
+#endif
+
#if __GNUC_PREREQ__(2, 96)
#define __malloc_like __attribute__((__malloc__))
#define __pure __attribute__((__pure__))
OpenPOWER on IntegriCloud