Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C programming Syntax

Is is possible to have this line of code ?

loops_per_msec = (1000000 * loops_per_msec / run_time ? :
        loops_per_msec);

My compiler gives me error although this line of code is exactly copied and pasted from other usable source file.

like image 510
Davy Avatar asked Dec 05 '25 12:12

Davy


1 Answers

The ternary conditional operator ?: takes three operands.

But GCC accepts, as an extension, to omit the middle operand.

In your case, coding

loops_per_msec = (1000000 * loops_per_msec / run_time ? run_time :
    loops_per_msec);

would make any compiler happy.

like image 87
Basile Starynkevitch Avatar answered Dec 07 '25 16:12

Basile Starynkevitch



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!