2013年1月7日月曜日

C++のstruct構造体

構造体structは幾つかのデータをひとまとめにしたものくらいにしか思っていなかったのですが、
C++ではsturuct構造体 と classクラスはデフォルトでのメンバへのアクセス制限(publicかprivate)が違うだけで同じものらしい。

/*
typedef struct {    // HostController EndPoint Descriptor
    __IO uint32_t Control; // +0 Endpoint descriptor control
    HCTD* TailTd;          // +4 Physical address of tail in Transfer descriptor list
    __IO HCTD* HeadTd;     // +8 Physcial address of head in Transfer descriptor list
    uint32_t Next;         // +12 Physical address of next Endpoint descriptor
} HCED;
*/

struct HCED {    // HostController EndPoint Descriptor
    __IO uint32_t Control; // +0 Endpoint descriptor control
    HCTD* TailTd;          // +4 Physical address of tail in Transfer descriptor list
    __IO HCTD* HeadTd;     // +8 Physcial address of head in Transfer descriptor list
    uint32_t Next;         // +12 Physical address of next Endpoint descriptor
};

試しにBaseUsbHost.hヘダーファイルでのHCEDの定義を書き換えてみたが動いた。
typedef していたのはCのUsbHostLiteからの残骸なのでしょう。

もちろん、classクラスと同等なのだからメンバ関数を持つことができる。
Controlへのアクセス、コンディションコード取得関数をHCED側に持つようにするとか,
メンバ変数からreinterpret_castで強引にキャストしていたのをインライン関数内でキャストするようにすれば
わかりやすいコードになると思う。

(2013/1/7)
---

0 件のコメント: