hudkmr hudkmr - 6 months ago 56
C Question

Type Casting in C language

How to typecast

(u32IDLHeaderAddress + FIOL__nFEEIDLHeaderLength)
to avoid constraint violation?

Function declaration -

Finit(const uint16 (*pastIDLTable)[2], uint16 u16NrOfDataset);

Function called -

Finit((u32IDLHeaderAddress + IDLHeaderLength),
(((*(uint32 *)(u32IDLHeaderAddress + 4) - FIOL__nFEEIDLHeaderLength)/4)));


For the provided function declaration, the first argument cast should look as follows

(const uint16 (*)[2]) (u32IDLHeaderAddress + IDLHeaderLength)

It is the first argument that seems to be producing the constraint violation, although it is hard to say without knowing the exact type of u32IDLHeaderAddress.

You for some reason seem to believe that it is the second one. The second argument looks fine to me - it already contains all casts it needs (although it appears to be a bit "overparenthesised").