←back to thread

327 points AareyBaba | 1 comments | | HN request time: 0.2s | source
Show context
time4tea ◴[] No.46184345[source]
a = a; // misra

Actual code i have seen with my own eyes. (Not in F-35 code)

Its a way to avoid removing an unused parameter from a method. Unused parameters are disallowed, but this is fine?

I am sceptical that these coding standards make for good code!

replies(11): >>46184442 #>>46184460 #>>46184571 #>>46185232 #>>46185373 #>>46186276 #>>46186377 #>>46186457 #>>46186510 #>>46186705 #>>46189488 #
unwind ◴[] No.46184460[source]
For C, the proper/expected/standard way to reference a variable without accessing it is a cast to void:

    (void) a;
I'm sure there are commonly-implemented compiler extensions, but this is the normal/native way and should always work.
replies(1): >>46185753 #
amluto ◴[] No.46185753[source]
Not if you use GCC.

https://godbolt.org/z/zYdc9ej88

clang gets this right.

replies(4): >>46185785 #>>46185906 #>>46191931 #>>46203376 #
1. account42 ◴[] No.46203376[source]
a) __attribute__((warn_unused_result)) is non-standard in the first place, are you looking for [[nodiscard]] - GCC does not warn on cast to void with that?

b) A return value that is explicitly marked like this is very different from an unused variable that gp suggested the cast to void idiom for. GCC does not warn on variables that are unused except for a cast to void.