calling other function, using return values

11OLSEN's icon

is there an example in the sdk? i have this function : `void nocturn_init(t_nocturn *x)
{
    struct usb_bus *busses;
struct usb_bus *bus;
struct usb_device *dev;

    usb_init();
usb_find_busses();
usb_find_devices();

busses = usb_get_busses();

for (bus = usb_get_busses(); bus; bus = bus->next)
{
for (dev = bus->devices; dev; dev = dev->next)
{
if (dev->descriptor.idVendor == MY_VID
&& dev->descriptor.idProduct == MY_PID)
{
object_post((t_object *)x, "found a Novation Nocturn device");
                object_post((t_object *)x, "Configurations : %i",dev->descriptor.bNumConfigurations);
                return usb_open(dev);
}
}
}
return NULL;
} `

how do i call this from another function and use the returned value?

Luigi Castelli's icon

Hi there,

if you want to return a generic pointer, you need to define the function as:

void *nocturn_init(t_nocturn *x);

Otherwise if usb_open(dev) returns a specific type, you could use

that as the function return type;

To call it from another function:void another_function(t_nocturn *x)
{
void *ret_ptr;
ret_ptr = nocturn_init(x);
}

Best.

- Luigi

11OLSEN's icon

thanks Luigi, i sorted that one out shortly after writing the thread, like so often..O.