cmisra

Is it safe to pass a uint32_t to a function which defines the input type as uint64_t?


Pass a uint32_t to a function that requires uint64_t: You can do this, and all compilers I know accept it, even in strict modes.

void MyFunction(uint64_t arg) {}

int main(void) {
    uint32_t xyz = 1u;
    MyFunction(xyz);
}

Solution


  • Is it safe to pass a uint32_t to a function which defines the input type as uint64_t?

    Yes. Yet see above notes.

    Is it explicitly allowed by the standard?

    Yes.

    Is it safe?

    Yes.

    What does MISRA-C say about this?

    Type sign-ness and value changes are things MISRA and well enabled compilers whine about.

    A sign-ness/value change does not occur in OP's code.