3 Replies Latest reply: Jan 5, 2017 2:18 AM by Timo Bräysy RSS

Parameter mismatch when compiling code as C++

Loren Garavaglia

I've been working with custom version of the wlan_mac_hcf model. Some of the work that I'm doing is easier to implement in C++ rather than C, so I checked the "Enable C++ Code Generation" option when I compile my code.  The C++ file was generated, but I received several compilation errors.  I've been able to resolve most of them, but I've received several instances of the following error that I can't seem to figure the cause of.


C:/OPNET/14.5.A/models/std/before GT30/wireless_lan/wlan_mac_hcf.pr.cpp(5062) : error C2664: 'prim_pk_fd_set_ptr' : cannot convert parameter 5 from 'void *(__cdecl *)(void *,unsigned int)' to 'SimT_Pk_Fd_Struct_Copy_Proc'

The code associated with this error is always the following function call:

op_pk_fd_set_ptr (wlan_transmit_frame_ptr, WLANC_CNTL_HEADER_FD, pk_chstruct_ptr, OPC_FIELD_SIZE_UNCHANGED, wlan_pk_chstruct_copy, wlan_pk_chstruct_destroy, sizeof (WlanT_Control_Header_Fields));

I'm not sure where the types referenced in the error come from, so I'm not really sure how to solve the error. 

Could this be an issue with the way that I attempted to generate the C++ code or is there something else causing the error?

  • Re: Parameter mismatch when compiling code as C++
    Paul Conway


      I have not seen your compilation error before but it does appear to be due to generating C++ code from C code


    .  Specifically, it may be due to function name mangling.  (See Wikipedia articlehttp://en.wikipedia.org/wiki/Name_mangling)


      The problem functions are declared in <OPNET>\models\std\include\wlan_support.h:

       void *wlan_pk_chstruct_copy(void * org_ptr, size_t size)

       void wlan_pk_chstruct_destroy(void * ptr)


      The above header file surrounds the declarations with extern "C" { ... }.  This usually addresses the mangling issue.  So we need to look elsewhere.


      Are you using the standard implementation in <OPNET>\models\std\wireless_lan\wlan_support.ex.c?  If you want to re-implement these functions, you might need a new name for them.


      The type "SimT_Pk_Fd_Struct_Copy_Proc" is declared in <OPNET>\sys\include\p_pk_type.h


      In 17.5, the size parameter is a size_t, but the error is looking for an unsigned int.  It is possible this difference is causing comiler to complain.  The C++ compiler may have a built in size_t type, where the C compiler is using a #define to declare size_t as an unsigned int.


      Does your wlan_mac_hcf model declare wlan_support as an external file?  If not, it may not be linking correctly.


      I hope I have shed some light onto the problem.  Good luck.

    • Re: Parameter mismatch when compiling code as C++
      Loren Garavaglia

      Hi Phil,

      Thanks for the response.  You were on the right track, however I did not specify in my question that I am still using version 14.5 of the software and that probably would have helped clear up some confusion. The function prototype and definition for wlan_pk_chstruct_copy in 14.5 declares size as an unsigned int rather than type size_t. SimT_Pk_Fd_Struct_Copy_Proc however expects a value of type size_t. I'm not sure why this wasn't a problem when I was compiling the project in C rather than C++, you might be correct in that the C compiler is using a #define.


      What I did to resolve the errors was go into the wlan_support.h and wlan_support.ex.c files and change the type for the size argument of the functions wlan_pk_chstruct_copy, wlan_pk_dhstruct_copy, and wlan_pk_bbstruct_copy as these were the functions causing the errors.


      I am not sure if this change will cause any logical issues when running my code.  I wasn't really familiar with the size_t type, but looking at documentation it seems like it is also an unsigned integer. Do you know of any issues my changes might cause?  I would think that if 17.5 uses size_t, I am probably relative safe in using it for these functions a well.