2013-05-19 5 views
1
static struct dll_wifi_state **dll_states; 

    enum dll_type { 
     DLL_UNSUPPORTED, 
     DLL_ETHERNET, 
     DLL_WIFI 
    }; 

    struct dll_state { 
     enum dll_type type; 

     union { 
     struct dll_eth_state *ethernet; 
     struct dll_wifi_state *wifi; 
     } data; 
    }; 

    static struct dll_state *dll_states = NULL; 

struct dll_wifi_state { 
    int link; 

    // A pointer to the function that is called to pass data up to the next layer. 
    up_from_dll_fn_ty nl_callback; 

    bool is_ds; 

}; 

이 포인터는 dll_wifi_state 구조체에서 전달되는 메서드입니다. 다른 파일에서 호환되지 않는 포인터 형식의 인수 전달

static void up_from_dll(int link, const char *data, size_t length) 
{ 
//some code here 
} 

, 나는

void reboot_accesspoint() 
{ 
    // We require each node to have a different stream of random numbers. 
    CNET_srand(nodeinfo.time_of_day.sec + nodeinfo.nodenumber); 

    // Provide the required event handlers. 
    CHECK(CNET_set_handler(EV_PHYSICALREADY, physical_ready, 0)); 

    // Prepare to talk via our wireless connection. 
    CHECK(CNET_set_wlan_model(my_WLAN_model)); 

    // Setup our data link layer instances. 
    dll_states = calloc(nodeinfo.nlinks + 1, sizeof(struct dll_state)); 

    for (int link = 0; link <= nodeinfo.nlinks; ++link) { 
    switch (linkinfo[link].linktype) { 
     case LT_LOOPBACK: 
     dll_states[link].type = DLL_UNSUPPORTED; 
     break; 

     case LT_WAN: 
     dll_states[link].type = DLL_UNSUPPORTED; 
     break; 

     case LT_LAN: 
     dll_states[link].type = DLL_ETHERNET; 
     dll_states[link].data.ethernet = dll_eth_new_state(link, up_from_dll); 
     break; 

     case LT_WLAN: 
     dll_states[link].type = DLL_WIFI; 
     dll_states[link].data.wifi = dll_wifi_new_state(link, 
                 up_from_dll, 
                 true /* is_ds */); 
     break; 
    } 
    } 

    // printf("reboot_accesspoint() complete.\n"); 
} 

그것은이 같은 잘 작동하지만 내가 다른 인수를 추가 할 예 up_from_dll ((INT 링크, CONST 문자 * 데이터를 size_t 길이이 메서드를 호출하고 ., INT의 서열) 그리고 최대한 빨리이 인수를 추가 할 때, 다음과 같은 오류가 시작이

ap.c:153: warning: passing argument 2 of ‘dll_wifi_new_state’ from incompatible pointer type 

오고 ??? 내가 포인터 정말 나쁜 오전 오류가 발생하지 않고 그 방법에 또 다른 인수를 추가하는 방법이 있나요 : (

도움을 주시면 감사하겠습니다.

라인 (153) :

dll_states[link].data.wifi = dll_wifi_new_state(link, 
                  up_from_dll, 
                  true /* is_ds */); 

및 방법

struct dll_wifi_state *dll_wifi_new_state(int link, 
              up_from_dll_fn_ty callback, 
              bool is_ds) 
{ 
    // Ensure that the given link exists and is a WLAN link. 
    if (link > nodeinfo.nlinks || linkinfo[link].linktype != LT_WLAN) 
    return NULL; 

    // Allocate memory for the state. 
    struct dll_wifi_state *state = calloc(1, sizeof(struct dll_wifi_state)); 

    // Check whether or not the allocation was successful. 
    if (state == NULL) 
    return NULL; 

    // Initialize the members of the structure. 
    state->link = link; 
    state->nl_callback = callback; 
    state->is_ds = is_ds; 

    return state; 
} 

내가 up_from_dll 할 수있는 새로운 매개 변수를 추가 떨어져 아무 것도 변경되지 않았습니다.

+0

나는 이제 이해하고 명확한 답변으로 내 답변을 업데이트합니다. ~. – xaxxon

답변

2

dll_wifi_new_state의 두 번째 매개 변수는 up_from_dll_fn_ty callback입니다.

그것은, 그것은 당신의 코드가 지금 목록에없는,하지만 up_from_dll_fn_ty는 타입 정의는 up_from_dll_fn_ty 당신이 다른 매개 변수를 up_from_dll 업데이트 할 때

(int seq을 포함하지 않음) 특정 매개 변수와 함수 포인터이라고 말하고있다 up_from_dll_fn_ty에 지정된 유형과 더 이상 일치하지 않으며 dll_wifi_new_state의 두 번째 매개 변수로 기대됩니다. up_from_dll_fn_ty에 매개 변수를 추가해야합니다. 그러면 좋을 것입니다.

up_from_dll_fn_ty의 정의를 게시하면 질문에 모든 정보가 포함되어있어 여전히 필요한 경우 더 많은 도움을 줄 수 있습니다.

: 함수 포인터에 대한 형식 정의를 만드는 방법에 대한 좋은 정보가있는 질문에 대한 링크가있어

typedef void (*up_from_dll_fn_ty)(int link, const char *data, size_t length); 

하고 여기에

typedef void (*up_from_dll_fn_ty)(int link, const char *data, size_t length, int seq); 

로 변경 :

당신은 같은 뭔가를 찾고있어

Understanding typedefs for function pointers in C

+0

줄 153 : dll_states [link] .data.wifi = dll_wifi_new_state (링크, up_from_dll, 참/* is_ds * /); – user2398101

+0

구조체 dll_wifi_state * dll_wifi_new_state (INT 링크 up_from_dll_fn_ty 콜백 부울 is_ds) { 경우를 (링크> nodeinfo.nlinks || linkinfo [링크] .linktype!= LT_WLAN) NULL을 반환합니다. 구조체 dll_wifi_state * state = calloc (1, sizeof (struct dll_wifi_state)); if (상태 == NULL) NULL을 반환합니다. // 구조체의 멤버를 초기화합니다. 상태 -> 링크 = 링크; 상태 -> nl_callback = 콜백; 상태 -> is_ds = is_ds; return 상태; } – user2398101

+0

dll_wifi_state는 데이터 링크 계층의 패킷을 다음 계층으로 전달하기 위해 up_from_dll()을 호출합니다. 'seq'숫자는 수신 된 메시지가 예상 메시지인지 여부를 확인한 후 다음 계층으로 보냅니다. – user2398101

관련 문제