MISRA C rules 10.3 and 10.4

Started by Eirik Midttun August 7, 2007
On Aug 8, 1:27 pm, Hans-Bernhard Br=F6ker <HBBroe...@t-online.de> wrote:
> David Brown wrote: > > If the emphasis had been on explicit casting, it would have made sense - > > "the value may only be *explicitly cast* to a type that is narrower, not > > implicitly", then it would have made sense. But (according to the above > > link),Misra-C allows: > > > u16x =3D (U16)(u32a + u32b); > > > but not: > > > u32x =3D (U32)(u16a + u16b); > > If so, that's quite positive achievement. Too many people believe that > > u16a =3D 40000; > u16b =3D 40000; > u32x =3D (U32)(u16a + u16b); > > will end up with u32x =3D 80000. IfMISRAcan invent rules that trigger > on precisely this case and convince those people to write what they > actually wanted: > > u32x =3D (U32) u16a + (U32) u16b; > > that would be a very good thing indeed.
I posted this reply on MISRA-Cs forum because it was the best answer I could find in the thread. They have now answered: "10.3 and 10.4 do apply to explicit casts. They are in the section 6=2E10.7 entitled "Explicit conversions (casts)". Therefore the example above clearly illustrates the intent of MISRA-C and is correct in its reasoning." So I think that will conclude the discussion. Thanks for the contributions everyone. - Eirik