You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by da...@apache.org on 2021/08/27 15:55:53 UTC
[incubator-nuttx] branch master updated: stddef: Let `offset` be
defined from toolchain
This is an automated email from the ASF dual-hosted git repository.
davids5 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 3c58b01 stddef: Let `offset` be defined from toolchain
3c58b01 is described below
commit 3c58b017216f6f6748e567c38bd49be8621684cc
Author: zhuyanlin <zh...@xiaomi.com>
AuthorDate: Fri Aug 27 10:41:53 2021 +0800
stddef: Let `offset` be defined from toolchain
Let `offset` could be defined from toolchain,
Which will be usefull for fixed code project.
---
include/nuttx/compiler.h | 24 ++++++++++++++++++++++++
include/stddef.h | 22 ----------------------
2 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h
index b7c2cf4..0cf3d3e 100644
--- a/include/nuttx/compiler.h
+++ b/include/nuttx/compiler.h
@@ -53,6 +53,22 @@
/* Built-in functions */
+/* The <stddef.h> header shall define the following macros:
+ *
+ * offsetof(type, member-designator)
+ * Integer constant expression of type size_t, the value of which is the
+ * offset in bytes to the structure member (member-designator), from the
+ * beginning of its structure (type).
+ *
+ * NOTE: This version of offsetof() depends on behaviors that could be
+ * undefined for some compilers. It would be better to use a builtin
+ * function if one exists.
+ *
+ * Reference: Opengroup.org
+ */
+
+# define offsetof(a, b) __builtin_offsetof(a, b)
+
/* GCC 4.x have __builtin_ctz(|l|ll) and __builtin_clz(|l|ll). These count
* trailing/leading zeros of input number and typically will generate few
* fast bit-counting instructions. Inputting zero to these functions is
@@ -491,6 +507,8 @@
# define UNUSED(a) ((void)(1 || (a)))
+# define offsetof(a, b) ((size_t)(&(((a *)(0))->b)))
+
/* Zilog-specific definitions ***********************************************/
#elif defined(__ZILOG__)
@@ -626,6 +644,8 @@
# define UNUSED(a) ((void)(1 || (a)))
+# define offsetof(a, b) ((size_t)(&(((a *)(0))->b)))
+
/* ICCARM-specific definitions **********************************************/
#elif defined(__ICCARM__)
@@ -690,6 +710,8 @@
# undef CONFIG_HAVE_ANONYMOUS_STRUCT
# undef CONFIG_HAVE_ANONYMOUS_UNION
+# define offsetof(a, b) ((size_t)(&(((a *)(0))->b)))
+
/* Unknown compiler *********************************************************/
#else
@@ -742,6 +764,8 @@
# define UNUSED(a) ((void)(1 || (a)))
+# define offsetof(a, b) ((size_t)(&(((a *)(0))->b)))
+
#endif
/****************************************************************************
diff --git a/include/stddef.h b/include/stddef.h
index 6e4a355..773f822 100644
--- a/include/stddef.h
+++ b/include/stddef.h
@@ -31,28 +31,6 @@
* Pre-processor Definitions
****************************************************************************/
-/* The <stddef.h> header shall define the following macros:
- *
- * NULL
- * The null pointer constant.
- *
- * NOTE: Currently the definition of NULL is in sys/types.h but should
- * be moved here sometime.
- *
- * offsetof(type, member-designator)
- * Integer constant expression of type size_t, the value of which is the
- * offset in bytes to the structure member (member-designator), from the
- * beginning of its structure (type).
- *
- * NOTE: This version of offsetof() depends on behaviors that could be
- * undefined for some compilers. It would be better to use a builtin
- * function if one exists.
- *
- * Reference: Opengroup.org
- */
-
-#define offsetof(a, b) ((size_t)(&(((a *)(0))->b)))
-
/****************************************************************************
* Type Definitions
****************************************************************************/