Cynerd commented on code in PR #19242:
URL: https://github.com/apache/nuttx/pull/19242#discussion_r3498997995


##########
libs/libc/limits_check.c:
##########
@@ -0,0 +1,195 @@
+/****************************************************************************
+ * libs/libc/limits_check.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* NuttX prefers defining limits per architecture directly as constants
+ * instead of using compiler provided definitions. That is to support
+ * compilers that do not provide such definitions. On the other hand in case
+ * compiler provides these definitions we should not deviate from them. This
+ * file thus contains only checks of NuttX's defined limits against compiler
+ * definitions if available.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+
+#include <limits.h>
+#include <float.h>
+
+/****************************************************************************
+ * Pre-processor Prototypes
+ ****************************************************************************/
+
+#ifdef static_assert
+#  define definition_assert(COMPILER_DEF, DEF) \
+  static_assert(COMPILER_DEF == DEF, "Compiler definition mismatch for " #DEF)
+#else
+#  define DEFINITION_ASSERT(COMPILER_DEF, DEF)
+#endif
+
+#ifdef __CHAR_BIT__
+definition_assert(__CHAR_BIT__, CHAR_BIT);

Review Comment:
   The idea was not to have it resolved every time the header is included. It 
is rather just a sanity check of our values, while the correct macros heavily 
depend on the compiler. It might make sense to add checks for other compilers 
as well, and at that point, it could get very long.
   
   If you think that it still makes sense to include these checks in their 
appropriate file (`limits.h` and `float.h`), then I can move them, of course. I 
just like the idea of performing these checks by the compiler only once.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to