Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
In the following function

C#
/*
 * Registrar structure information
 */
struct MTS_REGISTRAR_STRUCT_T
{
    MTS_SERVICE_ACCESS_POINT_T* pt_SAP;
    MTS_NODE_ID_T mt_NodeId;
    MTS_SUBJECT_ID_T mt_SubjectId;
    void* p_Buffer;
    SIZE_T t_BufferSize;
    void (*pt_CallBack)
    (
        MTS_SERVICE_ACCESS_POINT_T* pt_SAP,
        MTS_CALLBACK_DATA_T* pt_CallbackData,
        SOIS_STATUS_T* pt_Return
    );
    PRIORITY_T t_Priority;
    SOIS_QoS_T t_QoS;
    void* pt_Param;
};

void sois_mts_sap_init
(
    MTS_SERVICE_ACCESS_POINT_T *pt_SAP,
    MTS_MIB_T* pt_MIB,
    const APPLICATION_ID_T t_AppID,
    const void* pt_Param,
    SOIS_STATUS_T* pt_Result
)
{
    // If there is an error incoming, exit and propagate to the next
    if(*pt_Result != SOIS_STATUS_SUCCESS)
    {
            return;
    }
    // Assign MIB pointer
    pt_SAP->pt_MIB = pt_MIB;
    pt_SAP->mt_Id = t_AppID;
    pt_SAP->pt_Param = pt_Param;

}


At the line pt_SAP->pt_Param = pt_Param; I get the warning "assignment discards qualifiers from pointer target type". I know that if I remove the const from void* pt_Param, the warning goes away.

I would like to understand why

Thanks you so much in advance
Posted

1 solution

You only have a const void* and assign that to a void*. Hence you can modify the target with pt_SAP->pt_param although you could not with pt_Param. This breaks the contract of the function parameter declaration, which "promises" not to modify the object to which pt_Param pointer. And hence the warning.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Jul-13 11:12am    
Nice explanation, 5ed.
—SA
nv3 23-Jul-13 11:18am    
Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900