You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/09/07 05:03:36 UTC

[GitHub] [incubator-nuttx] buyuer opened a new pull request, #7028: Add some utility functions for nuttx.h

buyuer opened a new pull request, #7028:
URL: https://github.com/apache/incubator-nuttx/pull/7028

   add min_t,max_t,min3_t,ma3_t,swap_t macro functions for include/nuttx/nuttx.h


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] buyuer commented on a diff in pull request #7028: Add some utility functions for nuttx.h

Posted by GitBox <gi...@apache.org>.
buyuer commented on code in PR #7028:
URL: https://github.com/apache/incubator-nuttx/pull/7028#discussion_r964471128


##########
include/nuttx/nuttx.h:
##########
@@ -48,4 +48,83 @@
 #define container_of(ptr, type, member) \
   ((type *)((uintptr_t)(ptr) - offsetof(type, member)))
 
+/* Name: max_t
+ *
+ * Description:
+ *   return maximum of two values, using the specified type
+ *
+ * Arguments:
+ *   type - data type to use
+ *   x    - first value
+ *   y    - second value
+ */
+
+#ifndef max_t
+#define max_t(type, x, y) ({               \
+        type _max1 = (x);                  \
+        type _max2 = (y);                  \
+        _max1 > _max2 ? _max1 : _max2; })

Review Comment:
   But there'a not use the keyword of typeof



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] hartmannathan commented on a diff in pull request #7028: Add some utility functions for nuttx.h

Posted by GitBox <gi...@apache.org>.
hartmannathan commented on code in PR #7028:
URL: https://github.com/apache/incubator-nuttx/pull/7028#discussion_r964830723


##########
include/nuttx/nuttx.h:
##########
@@ -48,4 +48,83 @@
 #define container_of(ptr, type, member) \
   ((type *)((uintptr_t)(ptr) - offsetof(type, member)))
 
+/* Name: max_t
+ *
+ * Description:
+ *   return maximum of two values, using the specified type
+ *
+ * Arguments:
+ *   type - data type to use
+ *   x    - first value
+ *   y    - second value
+ */
+
+#ifndef max_t
+#define max_t(type, x, y) ({               \
+        type _max1 = (x);                  \
+        type _max2 = (y);                  \
+        _max1 > _max2 ? _max1 : _max2; })

Review Comment:
   We need to honor C89 standard since NuttX supports architectures that use C89 compilers without support for C99 and up.
   
   I wonder what is the motivation for adding these macros? Is it for use in NuttX common code? I understand that the ordinary min() and max() macros evaluate their arguments more than once and the above max_t() evaluates each argument once; but do we really need this for use within NuttX?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] buyuer commented on a diff in pull request #7028: Add some utility functions for nuttx.h

Posted by GitBox <gi...@apache.org>.
buyuer commented on code in PR #7028:
URL: https://github.com/apache/incubator-nuttx/pull/7028#discussion_r965452477


##########
include/nuttx/nuttx.h:
##########
@@ -48,4 +48,83 @@
 #define container_of(ptr, type, member) \
   ((type *)((uintptr_t)(ptr) - offsetof(type, member)))
 
+/* Name: max_t
+ *
+ * Description:
+ *   return maximum of two values, using the specified type
+ *
+ * Arguments:
+ *   type - data type to use
+ *   x    - first value
+ *   y    - second value
+ */
+
+#ifndef max_t
+#define max_t(type, x, y) ({               \
+        type _max1 = (x);                  \
+        type _max2 = (y);                  \
+        _max1 > _max2 ? _max1 : _max2; })

Review Comment:
   Indeed, it may not be so need



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] buyuer commented on a diff in pull request #7028: Add some utility functions for nuttx.h

Posted by GitBox <gi...@apache.org>.
buyuer commented on code in PR #7028:
URL: https://github.com/apache/incubator-nuttx/pull/7028#discussion_r964564019


##########
include/nuttx/nuttx.h:
##########
@@ -48,4 +48,83 @@
 #define container_of(ptr, type, member) \
   ((type *)((uintptr_t)(ptr) - offsetof(type, member)))
 
+/* Name: max_t
+ *
+ * Description:
+ *   return maximum of two values, using the specified type
+ *
+ * Arguments:
+ *   type - data type to use
+ *   x    - first value
+ *   y    - second value
+ */
+
+#ifndef max_t
+#define max_t(type, x, y) ({               \
+        type _max1 = (x);                  \
+        type _max2 = (y);                  \
+        _max1 > _max2 ? _max1 : _max2; })

Review Comment:
   Oh, I understand what you mean, this is indeed a problem. It can only work in the GCC compiler. If practical standard C, then it can only be implemented by functions, not macro. Do you have a good suggestion?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] buyuer commented on a diff in pull request #7028: Add some utility functions for nuttx.h

Posted by GitBox <gi...@apache.org>.
buyuer commented on code in PR #7028:
URL: https://github.com/apache/incubator-nuttx/pull/7028#discussion_r964576859


##########
include/nuttx/nuttx.h:
##########
@@ -48,4 +48,83 @@
 #define container_of(ptr, type, member) \
   ((type *)((uintptr_t)(ptr) - offsetof(type, member)))
 
+/* Name: max_t
+ *
+ * Description:
+ *   return maximum of two values, using the specified type
+ *
+ * Arguments:
+ *   type - data type to use
+ *   x    - first value
+ *   y    - second value
+ */
+
+#ifndef max_t
+#define max_t(type, x, y) ({               \
+        type _max1 = (x);                  \
+        type _max2 = (y);                  \
+        _max1 > _max2 ? _max1 : _max2; })

Review Comment:
   Can we use c11 in nuttx? If we can, we use Generic selection: https://en.cppreference.com/w/c/language/generic



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #7028: Add some utility functions for nuttx.h

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7028:
URL: https://github.com/apache/incubator-nuttx/pull/7028#discussion_r964460446


##########
include/nuttx/nuttx.h:
##########
@@ -48,4 +48,83 @@
 #define container_of(ptr, type, member) \
   ((type *)((uintptr_t)(ptr) - offsetof(type, member)))
 
+/* Name: max_t
+ *
+ * Description:
+ *   return maximum of two values, using the specified type
+ *
+ * Arguments:
+ *   type - data type to use
+ *   x    - first value
+ *   y    - second value
+ */
+
+#ifndef max_t
+#define max_t(type, x, y) ({               \
+        type _max1 = (x);                  \
+        type _max2 = (y);                  \
+        _max1 > _max2 ? _max1 : _max2; })

Review Comment:
   this seems to be GCC specific only



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #7028: Add some utility functions for nuttx.h

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7028:
URL: https://github.com/apache/incubator-nuttx/pull/7028#discussion_r964538014


##########
include/nuttx/nuttx.h:
##########
@@ -48,4 +48,83 @@
 #define container_of(ptr, type, member) \
   ((type *)((uintptr_t)(ptr) - offsetof(type, member)))
 
+/* Name: max_t
+ *
+ * Description:
+ *   return maximum of two values, using the specified type
+ *
+ * Arguments:
+ *   type - data type to use
+ *   x    - first value
+ *   y    - second value
+ */
+
+#ifndef max_t
+#define max_t(type, x, y) ({               \
+        type _max1 = (x);                  \
+        type _max2 = (y);                  \
+        _max1 > _max2 ? _max1 : _max2; })

Review Comment:
   I mean not a typeof, but https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] buyuer closed pull request #7028: Add some utility functions for nuttx.h

Posted by GitBox <gi...@apache.org>.
buyuer closed pull request #7028: Add some utility functions for nuttx.h
URL: https://github.com/apache/incubator-nuttx/pull/7028


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org