Adds several resolutions around endianess #505
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I dug a little deeper into how endianess works and I propose some modifications, tell me what you think.
Endianess detection at compile time
Concerning endianess, this can be detected in two ways
echo | gcc -dM -E - | grep ENDIAN
orecho | clang -dM -E - | grep ENDIAN
We can see example to check endianess here:
If not detected, throw an error to force the user to set it. The user will therefore be able to control the endianess depending on the unsupported compiler or standard he use.
Use build-in "swap" function when available
I added a way to detect the header
byteswap.h
with__has_include
. It is maybe not used by all compilers, it is worth it ?TriceReverse16
andTriceReverse32
can use the appropiate build-in when available and use C implementation if not found. More implementation can be done.The user can stil defined custom
TRICE_HTOTS
,TRICE_HTOTL
andTRICE_TTOHS
if no option at allNotes:
I removed macros swap option. When using "static inline" functions, the compiler will do the same job as a macros. I do some tests on godbolt. Of course, optimisation level change the behavior but user can set it and use other compiler option to force inlining if needed with
TRICE_INLINE
.When searching to support endianess, i found this information that give some compilers names used for embedded systems. Supported compilers and tools:
I didn't found if all of them are supported "BYTE_ORDER" variants but it can be a good to check if possible and add the support if it is possible. Otherwise the user need to defined what is needed.