-
Notifications
You must be signed in to change notification settings - Fork 72
Implement a STATIC_ASSERT macro #478
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
api/inc/uvisor_exports.h
Outdated
| * is known from c++11 while mbed-os compiles with c++98 | ||
| */ | ||
| #define UVISOR_STATIC_ASSERT(cond, msg) | ||
| #ifdef __cplusplus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use a different ifdef here.
Consider checking for C11 (__STDC_VERSION) first, and then falling back to other implementations.
api/inc/uvisor_exports.h
Outdated
| #define UVISOR_STATIC_ASSERT(cond, msg) typedef char STATIC_ASSERT_##msg[(cond)?1:-1] | ||
| #else | ||
| #define UVISOR_STATIC_ASSERT(cond, msg) _Static_assert(cond, #msg) | ||
| #endif/*__CPP__*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove /*__CPP__*/ comment. It's annoying to maintain and doesn't help much, since the ifdef is so small.
tools/uvisor-tests.txt
Outdated
| @@ -1 +1 @@ | |||
| 0ac4c38729d2602bff96d68983a7790143210912 No newline at end of file | |||
| 19ac0f1047d9bb7223fb8854f531968a8fe55d7b No newline at end of file | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to update uvisor-test.txt? What modifications to uvisor-test do you need to support UVISOR_STATIC_ASSERT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is an update to the head of the master branch of uvisor-tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please only update when needed.
- If you've made recent changes to the tests, also make a PR to uvisor to update the pointer.
- If you need changes in the tests for work on uvisor, update tests and then update your PR to uvisor to update the pointer in the same commit to uvisor that needs the change.
|
The fallback implementation is not working when Line 47 in bd3ec19
|
|
please squash the "fix code review" commit |
api/inc/uvisor_exports.h
Outdated
| #define UVISOR_STATIC_ASSERT(cond, msg) typedef char STATIC_ASSERT_##msg[(cond)?1:-1] | ||
| #endif | ||
| #else | ||
| #define UVISOR_STATIC_ASSERT(cond, msg) _Static_assert(cond, #msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use elseif to eliminate excessive nesting. Also, check that C is new enough for _Static_assert, and otherwise fallback to the typedef-based implementation.
bb1cd23 to
595b91b
Compare
api/inc/uvisor_exports.h
Outdated
| #define UVISOR_STATIC_ASSERT(cond, msg) | ||
| * The implementations differ due to compilation differences, C++ static_assert | ||
| * is known from C++11 (__cplusplus > 199711L) while mbed-os compiles with c++98, | ||
| * and C _Static_assert is known grom GCC version 4.6.0. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- grom
+ from17ac946 to
1e7fb3d
Compare
Implement STATIC_ASSERT macro to catch errors at compile time.
1e7fb3d to
4fee899
Compare
Implement STATIC_ASSERT macro to catch errors at compile time.