[clang] FEAT: 1 byte for "true" & "false" (PR #138713)
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 6 09:08:56 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: SAKSHAM JOSHI (saksham-joshi)
<details>
<summary>Changes</summary>
# In C language,
- the size of "true" and "false" macro is 4 bytes (for x64 arch)
- but the size of "bool" (typedef _Bool) is 1 byte.
- In order to decrease the memory usage, we can set the size of "true" and "false" macros to 1 byte using explicit typecasting in macro definition.
---
Full diff: https://github.com/llvm/llvm-project/pull/138713.diff
1 Files Affected:
- (modified) clang/lib/Headers/stdbool.h (+2-2)
``````````diff
diff --git a/clang/lib/Headers/stdbool.h b/clang/lib/Headers/stdbool.h
index dfaad2b65a9b5..4b81e4ba820d1 100644
--- a/clang/lib/Headers/stdbool.h
+++ b/clang/lib/Headers/stdbool.h
@@ -22,8 +22,8 @@
*/
#elif !defined(__cplusplus)
#define bool _Bool
-#define true 1
-#define false 0
+#define true ((bool)1)
+#define false ((bool)0)
#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Define _Bool as a GNU extension. */
#define _Bool bool
``````````
</details>
https://github.com/llvm/llvm-project/pull/138713
More information about the cfe-commits
mailing list