Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why formatting an int as 6*1000*1000 and not 6000000 [duplicate]

I was reading a code of a middleware that is written in c and in the code they wrote the following:

usleep(6*1000*1000);

So my question is:

Is there a reason behind writing it like this? why not just write 6000000? Doing this multiplication has any effect on the performance of the program?

like image 596
Loay Ashmawy Avatar asked Nov 30 '22 22:11

Loay Ashmawy


2 Answers

usleep() expects the supplied argument to be in "microseconds".

This is a visual transformation of the microsecond to seconds, no impact on code expected as any half-decent compiler will compute that at compile time.

like image 74
Sourav Ghosh Avatar answered Dec 04 '22 01:12

Sourav Ghosh


It just makes the source easier to read. With the multiplication, the number is obviously 6 million.

As it evaluates to a constant, the compiler will evaluate the constant at compile-time and there will be no difference in the compiled code.

like image 38
Graham Borland Avatar answered Dec 04 '22 01:12

Graham Borland