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/04/20 05:59:15 UTC

[GitHub] [incubator-nuttx] CV-Bowen opened a new pull request, #6108: assert: static_assert is not support in c standard C89,C99

CV-Bowen opened a new pull request, #6108:
URL: https://github.com/apache/incubator-nuttx/pull/6108

   ## Summary
   static_assert is not support in c standard C89,C99
   
   ## Testing
   CI
   


-- 
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] xiaoxiang781216 commented on a diff in pull request #6108: assert: static_assert is not support in c standard C89,C99

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


##########
include/assert.h:
##########
@@ -77,7 +77,11 @@
  */
 
 #ifndef __cplusplus
-#  define static_assert _Static_assert
+#  if __STDC_VERSION__  > 199901L

Review Comment:
   let's chang to
   '''
   #if defined(__STDC_VERSION__) && __STDC_VERSION__ > 199001L
   '''
   improve the compability.
   



-- 
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 #6108: assert: static_assert is not support in c standard C89,C99

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


##########
include/assert.h:
##########
@@ -77,7 +77,11 @@
  */
 
 #ifndef __cplusplus
-#  define static_assert _Static_assert
+#  if __STDC_VERSION__  > 199901L

Review Comment:
   probably this should be handled by `compiler.h`. I'm not sure if all compilers define `__STDC_VERSION__`. Need to double check.



-- 
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] xiaoxiang781216 merged pull request #6108: assert: static_assert is not support in c standard C89,C99

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #6108:
URL: https://github.com/apache/incubator-nuttx/pull/6108


-- 
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 #6108: assert: static_assert is not support in c standard C89,C99

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


##########
include/assert.h:
##########
@@ -77,7 +77,11 @@
  */
 
 #ifndef __cplusplus
-#  define static_assert _Static_assert
+#  if __STDC_VERSION__  > 199901L

Review Comment:
   Used searched a bit and found some construction
   ```
   # define static_assert(cond, msg)                   \
     extern int (*__Static_assert_function (void))             \
       [!!sizeof (struct { int __error_if_negative: (cond) ? 2 : -1; })]
   ```
   It is interesting if that can used for non-GCC that do not define `STDC_VERSION` or version is below required.
   I have not tried the code. Posting it here just for history.



-- 
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] xiaoxiang781216 commented on a diff in pull request #6108: assert: static_assert is not support in c standard C89,C99

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


##########
include/assert.h:
##########
@@ -77,7 +77,11 @@
  */
 
 #ifndef __cplusplus
-#  define static_assert _Static_assert
+#  if __STDC_VERSION__  > 199901L

Review Comment:
   let's chang to
   ```
   #if defined(__STDC_VERSION__) && __STDC_VERSION__ > 199001L
   ```
   improve the compability.
   



##########
include/assert.h:
##########
@@ -77,7 +77,11 @@
  */
 
 #ifndef __cplusplus
-#  define static_assert _Static_assert
+#  if __STDC_VERSION__  > 199901L

Review Comment:
   if the compiler doesn't support standard, `__STDC_VERSION__` shouldn't defined.



-- 
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 #6108: assert: static_assert is not support in c standard C89,C99

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


##########
include/assert.h:
##########
@@ -77,7 +77,11 @@
  */
 
 #ifndef __cplusplus
-#  define static_assert _Static_assert
+#  if __STDC_VERSION__  > 199901L

Review Comment:
   Ok. I've checked c89 with GCC:
   ```
   test.c:13:1: error: bit-field '__error_if_negative' has negative width (-1)
   static_assert(ABC == 2, "Error MSG");
   ^
   test.c:7:32: note: expanded from macro 'static_assert'
          [!!sizeof (struct { int __error_if_negative: (cond) ? 2 : -1; })]
                                  ^
   1 error generated
   ```
   and SDCC:
   ```
   test.c:13: error 176: sizeof applied to an incomplete type
   ```
   So I think anyway it is better than nothing :)



-- 
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] xiaoxiang781216 commented on a diff in pull request #6108: assert: static_assert is not support in c standard C89,C99

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


##########
include/assert.h:
##########
@@ -77,7 +77,11 @@
  */
 
 #ifndef __cplusplus
-#  define static_assert _Static_assert
+#  if __STDC_VERSION__  > 199901L

Review Comment:
   if the compiler doesn't support standard, __STDC_VERSION__ shouldn't defined.



-- 
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] CV-Bowen commented on a diff in pull request #6108: assert: static_assert is not support in c standard C89,C99

Posted by GitBox <gi...@apache.org>.
CV-Bowen commented on code in PR #6108:
URL: https://github.com/apache/incubator-nuttx/pull/6108#discussion_r854026156


##########
include/assert.h:
##########
@@ -77,7 +77,11 @@
  */
 
 #ifndef __cplusplus
-#  define static_assert _Static_assert
+#  if __STDC_VERSION__  > 199901L

Review Comment:
   As far as I know, the GCC and ICCARM define  `__STDC_VERSION__`, but i'm not sure the ZILOG and SDCC are the same. I will figure it out.



-- 
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] CV-Bowen commented on a diff in pull request #6108: assert: static_assert is not support in c standard C89,C99

Posted by GitBox <gi...@apache.org>.
CV-Bowen commented on code in PR #6108:
URL: https://github.com/apache/incubator-nuttx/pull/6108#discussion_r854721377


##########
include/assert.h:
##########
@@ -77,7 +77,11 @@
  */
 
 #ifndef __cplusplus
-#  define static_assert _Static_assert
+#  if __STDC_VERSION__  > 199901L

Review Comment:
   > if the compiler doesn't support c standard, `__STDC_VERSION__` shouldn't defined.
   
   Yes, i found it in http://open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf, Page-160
   
   > let's chang to
   > 
   > ```
   > #if defined(__STDC_VERSION__) && __STDC_VERSION__ > 199001L
   > ```
   > 
   > improve the compability.
   
   Ok.
   
   > Used searched a bit and found some construction
   > 
   > ```
   > # define static_assert(cond, msg)                   \
   >   extern int (*__Static_assert_function (void))             \
   >     [!!sizeof (struct { int __error_if_negative: (cond) ? 2 : -1; })]
   > ```
   > 
   > It is interesting if that can used for non-GCC that do not define `STDC_VERSION` or version is below required. I have not tried the code. Posting it here just for history.
   
   Interesting, i will try this.



-- 
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] xiaoxiang781216 commented on a diff in pull request #6108: assert: static_assert is not support in c standard C89,C99

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


##########
include/assert.h:
##########
@@ -77,7 +77,11 @@
  */
 
 #ifndef __cplusplus
-#  define static_assert _Static_assert
+#  if __STDC_VERSION__  > 199901L

Review Comment:
   if the compiler doesn't support c standard, `__STDC_VERSION__` shouldn't defined.



-- 
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 #6108: assert: static_assert is not support in c standard C89,C99

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


##########
include/assert.h:
##########
@@ -77,7 +77,11 @@
  */
 
 #ifndef __cplusplus
-#  define static_assert _Static_assert
+#  if __STDC_VERSION__  > 199901L

Review Comment:
   The source specifies that it should work for C 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] CV-Bowen commented on a diff in pull request #6108: assert: static_assert is not support in c standard C89,C99

Posted by GitBox <gi...@apache.org>.
CV-Bowen commented on code in PR #6108:
URL: https://github.com/apache/incubator-nuttx/pull/6108#discussion_r855081118


##########
include/assert.h:
##########
@@ -77,7 +77,11 @@
  */
 
 #ifndef __cplusplus
-#  define static_assert _Static_assert
+#  if __STDC_VERSION__  > 199901L

Review Comment:
   > Used searched a bit and found some construction
   > 
   > ```
   > # define static_assert(cond, msg)                   \
   >   extern int (*__Static_assert_function (void))             \
   >     [!!sizeof (struct { int __error_if_negative: (cond) ? 2 : -1; })]
   > ```
   > 
   > It is interesting if that can used for non-GCC that do not define `STDC_VERSION` or version is below required. I have not tried the code. Posting it here just for history.
   
   Done, @pkarashchenko 
   
   
   
   > let's chang to
   > 
   > ```
   > #if defined(__STDC_VERSION__) && __STDC_VERSION__ > 199001L
   > ```
   > 
   > improve the compability.
   
   Done, @xiaoxiang781216 



-- 
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 #6108: assert: static_assert is not support in c standard C89,C99

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


##########
include/assert.h:
##########
@@ -77,7 +77,11 @@
  */
 
 #ifndef __cplusplus
-#  define static_assert _Static_assert
+#  if __STDC_VERSION__  > 199901L

Review Comment:
   Ok. I've checked GCC:
   ```
   test.c:13:1: error: bit-field '__error_if_negative' has negative width (-1)
   static_assert(ABC == 2, "Error MSG");
   ^
   test.c:7:32: note: expanded from macro 'static_assert'
          [!!sizeof (struct { int __error_if_negative: (cond) ? 2 : -1; })]
                                  ^
   1 error generated
   ```
   and SDCC:
   ```
   test.c:13: error 176: sizeof applied to an incomplete type
   ```
   So I think anyway it is better than nothing :)



-- 
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