←back to thread

327 points AareyBaba | 8 comments | | HN request time: 0.289s | source | bottom
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 #
1. msla ◴[] No.46184442[source]
Especially since there is a widely recognized way to ignore a parameter:

    (void) a;
Every C programmer beyond weaning knows that.
replies(3): >>46184455 #>>46184487 #>>46184723 #
2. stefan_ ◴[] No.46184455[source]
I'm sure thats disallowed for the C-style cast.
replies(2): >>46184512 #>>46184585 #
3. ◴[] No.46184487[source]
4. daringrain32781 ◴[] No.46184512[source]
C++17 has the [[maybe_unused]] attribute.
5. cpgxiii ◴[] No.46184585[source]
Fwiw, unused-cast-to-void is a case that GCC and Clang ignore when using -Wno-old-style-cast, which is what most projects prohibiting C-style casts are going to be using (or whatever the equivalent their compiler provides).
6. time4tea ◴[] No.46184723[source]
The point really was that the unused method parameter should in almost all cases be removed, not that some trick should be used to make it seem used, and this is the wrong trick!
replies(2): >>46185208 #>>46190553 #
7. addaon ◴[] No.46185208[source]
Sometimes. But sometimes you have a set of functions that are called through function pointers that need the same signature, and one or more of them ignore some of the arguments. These days I’d spell that __attribute__((unused)); but it’s a perfectly reasonable case.
8. bluGill ◴[] No.46190553[source]

    #if otherbuild
        dosomething(param);
     #endif
the above type of thing happens once in a while. nos the paramater is needed but the normal build doesn't use it