Page 1 of 1

Syntax problem with struct and pointers

Posted: Mon Aug 10, 2020 6:03 pm
by dsteinwe
Hi,

I'm trying to use the interface "usb_ep0_callback_if" from the xmos usb lib. The function "get_interface_descriptor" of this interface has the weird parameter "const ep0_descriptor * unsafe &descs", I have no clue how to use. I am confused by using both operators together "*" and "&". "ep0_descriptor" is defined as:

Code: Select all

typedef struct ep0_descriptor {
  const char * unsafe desc;
  size_t len;
} ep0_descriptor;
I would expect, that I could use it like this:

Code: Select all

size_t my_len = 20;
unsafe {
	descs->desc = &my_array;
	desc->len = &my_len;
}
Unfortunately, it does not work. What is the right syntax? It would help me, if you explain the syntax.

Re: Syntax problem with struct and pointers

Posted: Sun Aug 16, 2020 4:27 am
by mon2
Try

Code: Select all

size_t my_len = 20;
unsafe {
	descs->desc = &my_array;
	descs->len = my_len;
}

Re: Syntax problem with struct and pointers

Posted: Mon Aug 17, 2020 8:20 am
by dsteinwe
What a stupid mistake! Have focused all the time on the string but "len" was the problem. Thanks mon2.