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 link, const char *data, size_t length, int seq) を追加したいのですが、この引数を追加するとすぐに、次のエラーが発生し始めます

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 に追加する以外は何も変更していません。

4

1 に答える 1

2

の 2 番目のパラメータdll_wifi_new_stateは ですup_from_dll_fn_ty callback

現在、コードリストにはありませんが、 が特定のパラメーターを持つ関数ポインターでup_from_dll_fn_tyあることを示す typedef ですup_from_dll_fn_ty(これには は含まれませんint seq) 。

異なるパラメータで更新すると、 で指定され、 の 2 番目のパラメータとして期待されるup_from_dllタイプと一致しなくなります。パラメータを追加する必要があり、うまくいくはずです。up_from_dll_fn_tydll_wifi_new_stateup_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);

関数ポインターの typedef の作成に関する適切な情報がある質問へのリンクを次に示します。

C の関数ポインターの typedef を理解する

于 2013-05-19T03:33:22.280 に答える