This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/CODECOMPOSER: argument of type "unsigned long *" is incompatible with parameter of type "uint32_t*"

Part Number: CODECOMPOSER

Tool/software: TI C/C++ Compiler

I am using the TI compiler in CCS version 8.0.0.00016. The code is being compiled for a Tiva 129X ARM processor. 

I have some code that declares some variables as "unsigned long", and then passes pointers to those variables as parameters to a TivaWare function that expects "uint32_t*" for the parameters. The compiler is complaining that the types are incompatible. However, according to the compiler manual, "unsigned long" is a 32-bit value. Why does the compiler generate a warning when the types are equivalent? And is there any way to fix this, short of disabling the warning message (which may result in me missing valid parameter type mismatches)?

Ordinarily, I would just change the unsigned long to uint32_t and be done with it. But I am trying to port legacy code written using a different compiler to CCS. There are hundreds of places this warning is going to occur.

Thanks for your help.

Regards,

Dave

  • Dave Hohl said:
    Why does the compiler generate a warning when the types are equivalent?

    Those types aren't strictly equivalent.  The type uint32_t is unsigned int, not unsigned long.  They are equivalent, in effect, because int and long are the same size.  For what it is worth, recent versions of GCC also produce a warning diagnostic in this case.

    Dave Hohl said:
    And is there any way to fix this, short of disabling the warning message (which may result in me missing valid parameter type mismatches)?

    An explicit cast to uint32_t will silence the diagnostic.  In this case, I recommend writing some macros that wrap the calls to the TivaWare functions.  Here is a simple example of what I mean.

    #include <stdint.h>
    
    void expects_ptr_uint32_t(uint32_t *ptr);
    #define WRAP_EXPECTS(arg) expects_ptr_uint32_t((uint32_t *)(arg))
    
    extern unsigned long ul;
    
    void test()
    {
       expects_ptr_uint32_t(&ul);  // diagnostic
       WRAP_EXPECTS(&ul);          // no diagnostic
    }

    Thanks and regards,

    -George

  • Thanks for the quick response, George. I guess the compiler used when developing the legacy code was more forgiving than CCS and GCC. I will just have to bite the bullet and clean up the existing code.

    Regards,

    Dave
  • For some reason when I replied, my response did not show up, even though it accepted the "resolved my issue" part. I want to thank you, George, for you quick response.

    Regards,

    Dave