-
Notifications
You must be signed in to change notification settings - Fork 274
C23 keywords #8623
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
C23 keywords #8623
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// _BitInt is a C23 feature | ||
|
||
// sizeof | ||
static_assert(sizeof(unsigned _BitInt(1)) == 1); | ||
static_assert(sizeof(_BitInt(32)) == 4); | ||
static_assert(sizeof(_BitInt(33)) == 8); | ||
static_assert(sizeof(_BitInt(65)) == 16); | ||
static_assert(sizeof(_BitInt(128)) == 16); | ||
|
||
int main() | ||
{ | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
_BitInt1.c | ||
--c23 | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
^CONVERSION ERROR$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// _BitInt is a C23 feature | ||
#include <assert.h> | ||
|
||
int main() | ||
{ | ||
// casts | ||
assert((_BitInt(4))17 == 1); | ||
assert((_BitInt(4)) - 1 == -1); | ||
assert((unsigned _BitInt(4)) - 1 == 15); | ||
|
||
// promotion (or lack thereof) | ||
assert((unsigned _BitInt(4))15 + (unsigned _BitInt(4))1 == 0); | ||
assert((unsigned _BitInt(4))15 + (unsigned _BitInt(5))1 == 16); | ||
assert((unsigned _BitInt(4))15 + (signed _BitInt(5))1 == -16); | ||
assert((unsigned _BitInt(4))15 + 1 == 16); | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
KNOWNBUG | ||
_BitInt2.c | ||
--c23 | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
^CONVERSION ERROR$ | ||
-- | ||
_BitInt implementation is missing. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// _BitInt is a C23 feature | ||
#include <assert.h> | ||
|
||
int main() | ||
{ | ||
// pointers | ||
_BitInt(3) x, *p = &x; | ||
*p = 1; | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
KNOWNBUG | ||
_BitInt3.c | ||
--c23 | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
^CONVERSION ERROR$ | ||
-- | ||
_BitInt implementation is missing. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// _BitInt is a C23 feature | ||
|
||
static_assert(6uwb + -6wb == 0); | ||
static_assert(sizeof(255uwb + 1uwb) == 1); | ||
static_assert(sizeof(0b1111'1111uwb) == 1); | ||
|
||
int main() | ||
{ | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
KNOWNBUG | ||
_BitInt4.c | ||
--c23 | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
^CONVERSION ERROR$ | ||
-- | ||
_BitInt implementation is missing. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// C23 predefined constants | ||
static_assert(!false, "false"); | ||
static_assert(true, "true"); | ||
static_assert(sizeof(false) == sizeof(bool), "sizeof false"); | ||
static_assert(sizeof(true) == sizeof(bool), "sizeof true"); | ||
static_assert(nullptr == 0, "nullptr"); | ||
|
||
int main() | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CORE | ||
predefined-constants1.c | ||
--c23 | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// C23 introduces the "static_assert" keyword. | ||
|
||
struct S | ||
{ | ||
// Visual Studio does not support static_assert in compound bodies. | ||
#ifndef _MSC_VER | ||
static_assert(1, "in struct"); | ||
#endif | ||
int x; | ||
} asd; | ||
|
||
static_assert(1, "global scope"); | ||
|
||
int main() | ||
{ | ||
static_assert(1, "in function"); | ||
} | ||
Comment on lines
+1
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this go in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that was my first attempt. But we run various compilers over that folder, and they don't do C23. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
static_assert1.c | ||
--c23 | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
^CONVERSION ERROR$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
typedef int INTTYPE; | ||
|
||
int func1(); | ||
|
||
// C23 typeof | ||
typeof(int) v1; | ||
typeof(INTTYPE) v2; | ||
typeof(v2) v3; | ||
typeof(1 + 1) v4; | ||
typeof(1 + 1 + func1()) v5; | ||
const typeof(int) v6; | ||
typeof(int) const v7; | ||
static typeof(int) const v8; | ||
static typeof(int) const *v9; | ||
static volatile typeof(int) const *v10; | ||
|
||
void func2(typeof(int) *some_arg) | ||
{ | ||
} | ||
|
||
int main() | ||
{ | ||
} | ||
Comment on lines
+1
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably go in |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
typeof2.c | ||
--c23 | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
^CONVERSION ERROR$ |
Uh oh!
There was an error while loading. Please reload this page.