Syntax problem with struct and pointers Topic is solved

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
User avatar
dsteinwe
Experienced Member
Posts: 66
Joined: Wed Jun 29, 2016 8:59 am

Syntax problem with struct and pointers

Postby dsteinwe » Mon Aug 10, 2020 6:03 pm

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.
View Solution
User avatar
mon2
XCore Legend
Posts: 1831
Joined: Thu Jun 10, 2010 11:43 am

Postby mon2 » Sun Aug 16, 2020 4:27 am

Try

Code: Select all

size_t my_len = 20;
unsafe {
	descs->desc = &my_array;
	descs->len = my_len;
}
User avatar
dsteinwe
Experienced Member
Posts: 66
Joined: Wed Jun 29, 2016 8:59 am

Postby dsteinwe » Mon Aug 17, 2020 8:20 am

What a stupid mistake! Have focused all the time on the string but "len" was the problem. Thanks mon2.

Who is online

Users browsing this forum: No registered users and 4 guests