-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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
Conversation
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.
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 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. |
@llvm/pr-subscribers-clang Author: SAKSHAM JOSHI (saksham-joshi) Changes1 byte is enough for bool
Full diff: https://github.com/llvm/llvm-project/pull/138649.diff 1 Files Affected:
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
|
@llvm/pr-subscribers-backend-x86 Author: SAKSHAM JOSHI (saksham-joshi) Changes1 byte is enough for bool
Full diff: https://github.com/llvm/llvm-project/pull/138649.diff 1 Files Affected:
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.
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.