[clang] FEAT: one byte for "true" & "false" (PR #138649)
https://github.com/saksham-joshi updated https://github.com/llvm/llvm-project/pull/138649 >From 8bba07d817d4dd583122d7ed831de276da8801e0 Mon Sep 17 00:00:00 2001 From: SAKSHAM JOSHI Date: Tue, 6 May 2025 12:43:34 +0530 Subject: [PATCH] FEAT: one byte for "true" & "false" 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. --- clang/lib/Headers/stdbool.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] FEAT: one byte for "true" & "false" (PR #138649)
https://github.com/saksham-joshi created https://github.com/llvm/llvm-project/pull/138649 ### 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. >From 8bba07d817d4dd583122d7ed831de276da8801e0 Mon Sep 17 00:00:00 2001 From: SAKSHAM JOSHI Date: Tue, 6 May 2025 12:43:34 +0530 Subject: [PATCH] FEAT: one byte for "true" & "false" 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. --- clang/lib/Headers/stdbool.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] FEAT: one byte for "true" & "false" (PR #138649)
https://github.com/saksham-joshi updated https://github.com/llvm/llvm-project/pull/138649 >From 8bba07d817d4dd583122d7ed831de276da8801e0 Mon Sep 17 00:00:00 2001 From: SAKSHAM JOSHI Date: Tue, 6 May 2025 12:43:34 +0530 Subject: [PATCH 1/2] FEAT: one byte for "true" & "false" 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. --- clang/lib/Headers/stdbool.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 >From 890f5b7cb698fe6ae167247ff6453940b8f71af9 Mon Sep 17 00:00:00 2001 From: SAKSHAM JOSHI Date: Tue, 6 May 2025 21:24:03 +0530 Subject: [PATCH 2/2] Update stdbool.h --- clang/lib/Headers/stdbool.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Headers/stdbool.h b/clang/lib/Headers/stdbool.h index e9142327f0ffd..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 (bool)1 -#define false (bool)0 +#define true ((bool)1) +#define false ((bool)0) #elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* Define _Bool as a GNU extension. */ #define _Bool bool ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] FEAT: one byte for "true" & "false" (PR #138649)
https://github.com/saksham-joshi updated https://github.com/llvm/llvm-project/pull/138649 Rate limit · GitHub body { background-color: #f6f8fa; color: #24292e; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol; font-size: 14px; line-height: 1.5; margin: 0; } .container { margin: 50px auto; max-width: 600px; text-align: center; padding: 0 24px; } a { color: #0366d6; text-decoration: none; } a:hover { text-decoration: underline; } h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; text-shadow: 0 1px 0 #fff; } p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; } ul { list-style: none; margin: 25px 0; padding: 0; } li { display: table-cell; font-weight: bold; width: 1%; } .logo { display: inline-block; margin-top: 35px; } .logo-img-2x { display: none; } @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and ( min--moz-device-pixel-ratio: 2), only screen and ( -o-min-device-pixel-ratio: 2/1), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) { .logo-img-1x { display: none; } .logo-img-2x { display: inline-block; } } #suggestions { margin-top: 35px; color: #ccc; } #suggestions a { color: #66; font-weight: 200; font-size: 14px; margin: 0 10px; } Whoa there! You have exceeded a secondary rate limit. Please wait a few minutes before you try again; in some cases this may take up to an hour. https://support.github.com/contact";>Contact Support — https://githubstatus.com";>GitHub Status — https://twitter.com/githubstatus";>@githubstatus ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] FEAT: 1 byte for "true" & "false" (PR #138713)
https://github.com/saksham-joshi created https://github.com/llvm/llvm-project/pull/138713 # 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. >From db8d4b5b102c9e1cf8d43d108858ede66baea82f Mon Sep 17 00:00:00 2001 From: SAKSHAM JOSHI Date: Tue, 6 May 2025 21:37:08 +0530 Subject: [PATCH] FEAT: 1 byte for "true" & "false" - 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. --- clang/lib/Headers/stdbool.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] FEAT: one byte for "true" & "false" (PR #138649)
https://github.com/saksham-joshi updated https://github.com/llvm/llvm-project/pull/138649 >From 8bba07d817d4dd583122d7ed831de276da8801e0 Mon Sep 17 00:00:00 2001 From: SAKSHAM JOSHI Date: Tue, 6 May 2025 12:43:34 +0530 Subject: [PATCH 1/3] FEAT: one byte for "true" & "false" 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. --- clang/lib/Headers/stdbool.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 >From 890f5b7cb698fe6ae167247ff6453940b8f71af9 Mon Sep 17 00:00:00 2001 From: SAKSHAM JOSHI Date: Tue, 6 May 2025 21:24:03 +0530 Subject: [PATCH 2/3] Update stdbool.h --- clang/lib/Headers/stdbool.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Headers/stdbool.h b/clang/lib/Headers/stdbool.h index e9142327f0ffd..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 (bool)1 -#define false (bool)0 +#define true ((bool)1) +#define false ((bool)0) #elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* Define _Bool as a GNU extension. */ #define _Bool bool >From 1ad7042ac9c09aa7274c9c40084fc496b5ed93a4 Mon Sep 17 00:00:00 2001 From: SAKSHAM JOSHI Date: Wed, 7 May 2025 07:40:16 +0530 Subject: [PATCH 3/3] FEAT: 1 byte for "true" & "false" 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. --- clang/lib/Headers/stdbool.h | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/lib/Headers/stdbool.h b/clang/lib/Headers/stdbool.h index 4b81e4ba820d1..0aa017e58c3c7 100644 --- a/clang/lib/Headers/stdbool.h +++ b/clang/lib/Headers/stdbool.h @@ -22,8 +22,10 @@ */ #elif !defined(__cplusplus) #define bool _Bool -#define true ((bool)1) -#define false ((bool)0) +#define true 1 +#define false 0 +#define true_1 ((bool)1) +#define false_1 ((bool)0) #elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* Define _Bool as a GNU extension. */ #define _Bool bool ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] FEAT: one byte for "true" & "false" (PR #138649)
https://github.com/saksham-joshi closed https://github.com/llvm/llvm-project/pull/138649 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] FEAT: 1 byte for "true" & "false" (PR #138713)
https://github.com/saksham-joshi closed https://github.com/llvm/llvm-project/pull/138713 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] FEAT: 1 byte for "true" & "false" (PR #138713)
saksham-joshi wrote: > > Yeah! you are right that the size depends on the variable, but I never said > > to create a variable. > > Suppose I have two functions performing same process but one is returning > > bool and other one is returning int. > > > > 1. bool fnc1() { return (_Bool)true; } > > 2. int fnc2(){ return true; } > > > > Can you please tell me which of the above 2 function will be more efficient? > > Again, in this case the "efficiency" of these functions does not depend on > how you declare true and false, but rather on what return type each function > has. > > But the impact of type change is also questionable. Per modern calling > conventions, the return value of a function is stored in a CPU register, and > the size of that register is usually 4 or 8 bytes. Even if one decides to > return a 1-byte value, there won't be much difference for the CPU. (Well, on > x86 you can return the 1-byte value in AL, but this won't lead to faster > code). > > > If this is also the case with Clang, then my work is done here. > > Yes, this is also the case. Okay, I got it! Thank you so much Mr. Ramosian Glider https://github.com/llvm/llvm-project/pull/138713 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits