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.

CCS warning for usage of function pointer

Other Parts Discussed in Thread: AM3359

Hi,

We are developing one machine control application on AM3359 ICE. This is basically a POC kind of project we are working on. Following is brief description about the issue

I am assigning a function pointer in a structure as

void(*function)(void *). But when I assign this pointer to any of the function e.g. ptr->function = &configure_232, I do get a warning

"#515-D a value of type "void (*)(ACTION_OBJECT *)" cannot be assigned to an entity of type "void (*)(void *)" general_functions.c /CTS_Panda/source line 977 C/C++ Problem

This warning is currently not stopping the program from execution of the appropriate function. But can anybody why this warning is coming? Is there any compiler setting that I need to do to remove this warning?

  • Hi Balwant,

    As long as the warning is not affecting your execution you can just neglect it. No need to dig deeper :)

    Regards,

    Gautam

  • The signature (type and number of arguments etc.) of the function pointer must match the signature of the function assigned to it.  This example should make it clear ...

    % type file.c
    struct {
       void(*function)(void *);
    } gs ;
    
    void works       (void *);
    void gets_warning(void  );
    
    void try_stuff_out()
    {
       gs.function = works;
       gs.function = gets_warning;
    }
    
    
    % armcl -mv7A8 --verbose_diagnostics --display_error_number file.c
    "file.c", line 11: warning #515-D: a value of type "void (*)(void)" cannot be
              assigned to an entity of type "void (*)(void *)"
         gs.function = gets_warning;
                     ^

    Thanks and regards,

    -George

  • Hi George ,

         If the Warning becomes the ERROR, how can I fix it ? Please Help me!

         Thank you in advance!

  • Bruce Lin1 said:
    If the Warning becomes the ERROR, how can I fix it ? Please Help me!

    The function signatures must match.  There are two approaches:

    1. Cast the address of the function right before assigning it
    2. Change the signature of the function which has its address used

    Use the approach which is least disruptive to your code.  This example builds on the previous one.  It uses the cast approach to avoid the diagnostic.

    % type file.c
    typedef void (* FPTR_RETURNS_VOID_ARG_VOIDPTR)(void *);
    
    struct {
       FPTR_RETURNS_VOID_ARG_VOIDPTR function;
    } gs ;
    
    void works       (void *);
    void gets_warning(void  );
    
    void try_stuff_out()
    {
       gs.function = works;
       gs.function = (FPTR_RETURNS_VOID_ARG_VOIDPTR) gets_warning;
    }
    
    
    % armcl -mv7A8 --verbose_diagnostics --display_error_number file.c
    
    %
    

    The type FPTR_RETURNS_VOID_ARG_VOIDPTR is a pointer to a function which returns void and takes an argument that is a void pointer.  It is used to declare the function pointer in the struct, and to cast the address of the function gets_warning, which does not match that function signature.

    Thanks and regards,

    -George

  • Hi George,
    Thank you so much! I really appreciate for your helping!
    Also I have another question, why the "works function" no need do the cast approach, like this: "gs.function = works;" . Only as the works function has the same parameter with FPTR_RETURNS_VOID_ARG_VOIDPTR?
    I am sorry to bother you again!
    Thank you for you in advance!
  • Bruce Lin1 said:
    why the "works function" no need do the cast approach, like this: "gs.function = works

    A function signature is the return type plus the number and type of the arguments.  A function pointer also has a signature.  That assignment does not need a cast because the signature of the function pointer (gs.function) matches the signature of the function being assigned (works).

    Thanks and regards,

    -George

  • Hi George,

      Thank you very much! I finaly understand it ! Thank you !