accessing Double pointer

…衆ロ難τιáo~ 提交于 2019-12-24 16:10:08

问题


typedef struct _WDF_USB_DEVICE_SELECT_CONFIG_PARAMS {

ULONG Size;

WdfUsbTargetDeviceSelectConfigType Type;

union {

struct {
  PUSB_CONFIGURATION_DESCRIPTOR  ConfigurationDescriptor;
  PUSB_INTERFACE_DESCRIPTOR*  InterfaceDescriptors;
  ULONG NumInterfaceDescriptors;
} Descriptor;
struct {
  PURB  Urb;
} Urb;
struct {
  UCHAR  NumberConfiguredPipes;
  WDFUSBINTERFACE  ConfiguredUsbInterface;
} SingleInterface;
struct {
  UCHAR  NumberInterfaces;
  PWDF_USB_INTERFACE_SETTING_PAIR  Pairs;
  UCHAR  NumberOfConfiguredInterfaces;
} MultiInterface;

} Types;

} WDF_USB_DEVICE_SELECT_CONFIG_PARAMS, *PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS;

WDF_USB_DEVICE_SELECT_CONFIG_PARAMS params;

typedef struct _USB_INTERFACE_DESCRIPTOR {

UCHAR bLength ;

UCHAR bInterfaceClass ;

UCHAR bInterfaceSubClass ;

} USB_INTERFACE_DESCRIPTOR, *PUSB_INTERFACE_DESCRIPTOR ;

Able to acess NumInterfaceDescriptors via -> params.Types.Descriptor.NumInterfaceDescriptors

I want to acess bInterfaceClass via WDF_USB_DEVICE_SELECT_CONFIG_PARAMS . Please note that this structure is filled by the library I have to just access it


回答1:


(*someIntDesc)->iInterface



回答2:


IntDesc foo;
// somehow initialize foo to actually point to (a pointer to) a valid structure
(*foo)->iInterface = 10;



回答3:


IntDesc is a type, not a variable. So the first thing you need to do is create a variable of the correct type:

IntDesc id;

Next, you'll need to have it point to allocated memory. I'm going to put everything on the stack, you may have other needs:

USB_INTERFACE_DESCRIPTOR usb;
PUSB_INTERFACE_DESCRIPTOR pusb = &usb;
id = &pusb;

Now that you have a valid pointer, you can go ahead an dereference it. Since this is a double pointer, you will need to dereference it twice:

(*(*id)).iInterface = 10;

Because C defines -> as a combination of * and ., you can express that more succinctly with:

(*id)->iInterface = 10; 



回答4:


From the name InterfaceDescriptors, it would appear to point to an array of pointers to the structure. So the more idiomatic way would be:

InterfaceDescriptors[0]->iInterface = 10;



回答5:


Deference it like this

(*intDesc)->iInterface



回答6:


Your code is quite wrong

NODE* ptr;
k.N.iInterface = 100;
ptr = (NODE*)malloc(sizeof(NODE));

And before accesing:

ptr->N1->iInterface

N1 should be initialized to something.



来源:https://stackoverflow.com/questions/2084077/accessing-double-pointer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!