Why formatting int like 6 * 1000 * 1000 and not 6000000

I read the middleware code written in c and in the code on which they wrote the following:

usleep(6*1000*1000); 

So my question is:

Is there a reason to write like this? why not just write 6,000,000? Does this multiplication affect program performance?

+5
source share
3 answers

usleep() expects the provided argument to be in microseconds.

This visual conversion of microseconds in seconds does not affect the expected code, since any semi-decent compiler will calculate this at compile time.

+8
source

It just makes reading the source easier. When multiplied, the number is obviously 6 million.

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

+7
source

Most likely, this was done for readability.

Looking at 6000000 in the code, you may not immediately see how many zeros are. The visual difference between this value and 60000000 or 600000 is small. Breaking it makes it easier to view.

Any decent compiler should calculate 6*1000*1000 at compile time, so there should be no performance impact.

+5
source

Source: https://habr.com/ru/post/1265617/


All Articles