Undefined behavior when passing a pointer to a function with a formal parameter of pointer to const?
I have been working on some code that is similar to the following:

    typedef struct
    {
        unsigned char x;
        unsigned short y;
        unsigned char[NUM_DEFINED_ELSEWHERE];
    } My_Struct;

    static My_Struct my_useful_struct;   // Variables initialized elsewhere in code.
    
    void myFunction(const My_Struct * p_my_struct)
    {
        /* Performs various read-only actions utilizing p_my_struct. */
    }

    void myOtherFunction(void)
    {
        static My_Struct p_struct = &my_useful_struct;
        myFunction(&p_struct);
    }

My code compiles without any problems, but when reviewed I was told that unless I typecast p_struct that this could lead to undefined behavior on certain platforms (i.e. 8051).  However, I never even received a warning on the compiler.  **Is it true that not typecasting the pointer when passing it to the function with `(const My_Struct *)` could lead to undefined behavior?**

The reason that I declared the above function with a pointer to `const` was because I wanted to be able to handle both a pointer to const and a pointer.  **Is it bad coding practice not to typecast in the above situation?**

Thanks for your help!
Undefined behavior when passing a pointer to a function with a formal parameter of pointer to const?
===

I have been working on some code that is similar to the following:

    typedef struct
    {
        unsigned char x;
        unsigned short y;
        unsigned char[NUM_DEFINED_ELSEWHERE];
    } My_Struct;

    static My_Struct my_useful_struct;   // Variables initialized elsewhere in code.
    
    void myFunction(const My_Struct * p_my_struct)
    {
        /* Performs various read-only actions utilizing p_my_struct. */
    }

    void myOtherFunction(void)
    {
        static My_Struct p_struct = &my_useful_struct;
        myFunction(&p_struct);
    }

My code compiles without any problems, but when reviewed I was told that unless I typecast p_struct that this could lead to undefined behavior on certain platforms (i.e. 8051).  However, I never even received a warning on the compiler.  **Is it true that not typecasting the pointer when passing it to the function with `(const My_Struct *)` could lead to undefined behavior?**

The reason that I declared the above function with a pointer to `const` was because I wanted to be able to handle both a pointer to const and a pointer.  **Is it bad coding practice not to typecast in the above situation?**

Thanks for your help!