Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FEAT: one byte for "true" & "false" #138649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed

Conversation

saksham-joshi
Copy link

1 byte is enough for bool

  • In C programming language,

  • the size of "true" and "false" macros is 4 byte and size of macro "bool" (typedef of _Bool) is 1 byte.

  • By this simple change, we can set the size of "true" and "false" to 1 byte.

  • This change will decrease the memory usage made by using true & false macros in C.

In C programming language,

The size of "true" and "false" macros is 4 byte and size of "_Bool" datatype is 1 byte.

By this simple change, we can set the size of "true" and "false" to 1 byte.
Copy link

github-actions bot commented May 6, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics labels May 6, 2025
@llvmbot
Copy link
Member

llvmbot commented May 6, 2025

@llvm/pr-subscribers-clang

Author: SAKSHAM JOSHI (saksham-joshi)

Changes

1 byte is enough for bool

  • In C programming language,

  • the size of "true" and "false" macros is 4 byte and size of macro "bool" (typedef of _Bool) is 1 byte.

  • By this simple change, we can set the size of "true" and "false" to 1 byte.

  • This change will decrease the memory usage made by using true & false macros in C.


Full diff: https://github.com/llvm/llvm-project/pull/138649.diff

1 Files Affected:

  • (modified) clang/lib/Headers/stdbool.h (+2-2)
diff --git a/clang/lib/Headers/stdbool.h b/clang/lib/Headers/stdbool.h
index dfaad2b65a9b5..e9142327f0ffd 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

@llvmbot
Copy link
Member

llvmbot commented May 6, 2025

@llvm/pr-subscribers-backend-x86

Author: SAKSHAM JOSHI (saksham-joshi)

Changes

1 byte is enough for bool

  • In C programming language,

  • the size of "true" and "false" macros is 4 byte and size of macro "bool" (typedef of _Bool) is 1 byte.

  • By this simple change, we can set the size of "true" and "false" to 1 byte.

  • This change will decrease the memory usage made by using true & false macros in C.


Full diff: https://github.com/llvm/llvm-project/pull/138649.diff

1 Files Affected:

  • (modified) clang/lib/Headers/stdbool.h (+2-2)
diff --git a/clang/lib/Headers/stdbool.h b/clang/lib/Headers/stdbool.h
index dfaad2b65a9b5..e9142327f0ffd 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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants