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.
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.
Well, yes, this might be wrong since the case here should be an integer constant expression.
However, you should improve your commit message, for example, which compiler you used, the compiler error (warning) messages like:
, and why the logical operator (i.e., -EINPROGRESS || -EBUSY) is not the integer constant expression.
Even though, the standard doesn't explicitly tell us that the logical operator is not the integer constant expression, and the GCC also doesn't yell about this.
The confusing point here is whether the evaluation of the logical operator happens at compile-time or runtime (it might be the implementation-defined). However, you need to explain to us why you want to change this properly.
I have no opposition to changing this code, but still, we need a good explanation to tell the following people why we are making this change.
Here are some links that might help you to write the message (you can even ask the ChatGPT to give suggestions, I think it is a good tool to explain the details of Standard), but you should see the Standard too.
https://en.cppreference.com/w/c/language/switch
https://en.cppreference.com/w/c/language/constant_expression
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.
Thanks for the long comment. I thought this is a straightforward one-line change and would not need a long description.
But yes, I can update my PR description later.
And to your question.
I am not sure if the compiler-time/runtime calculation is within some spec or just another compiler's UB/IB.
But the existing code is definitely wrong, no mater if it is a compile time calculation or not. Code like
x==(a||b)
will need to calculate the(a||b)
first and generate a bool-like value, which is 1 or 0 in C. There is almost no chance to be correct, unlessx
is 1 and one of thea
andb
is also 1.For a compiler, it is quite reasonable to perform the compile time static calculation. Both the error code are defined with
#define E_some 100
. To the compiler, the code is just likecase -100 || -200 :
at build time.I tried some different toll combination on godbolt. All of them are showing the same result: static calculation at compile time and the case-condition is to compare with 1.
godbolt link: https://godbolt.org/z/1rPrPdjoh
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.
Updated with PR description, please let me know if there is any other ambiguity in it.
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.
Ok. Thanks for more comprehensive explanations.
Now, we should add PR description to the commit message too. So people can see these information within the git source tree.
You can use the git amend and force push.
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.
git commit updated as well.