Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C -- passing array literal to a method

Tags:

objective-c

This seems to work (compiler doesn't complain, anyway):

float adsr[4] = {0,1.0/PULSE_SPEED, 0,1};
[sequence setBaseADSR:adsr];

but I want to make it more concise and do this:

[sequence setBaseADSR:{0,1.0/PULSE_SPEED, 0,1}];

How do I do it? In javascript, I'd call stuff in the brackets an "array literal". Not sure if C languages have the same concept or terminology though.

like image 392
morgancodes Avatar asked Dec 03 '25 10:12

morgancodes


1 Answers

If your compiler supports the C99 compound literal syntax, it's possible.

[sequence setBaseADRS:(float [4]){0,1.0/PULSE_SPEED,0,1}];
like image 124
Nietzche-jou Avatar answered Dec 07 '25 17:12

Nietzche-jou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!