Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do people say C is more efficient? [closed]

People always say that C is more efficient than any other high level language.I don't understand why. I know assembly is efficient because it has a close relation to machine language .

But C and C++ or ruby,lets say,they are all going to be 'translated' into machine language,right? By more efficient,does it mean the machine code is better,or it takes less time to be 'translated' into machine code? What if there is some compiler or interpreter that can produce faster,also result in better machine code?

like image 280
Gnijuohz Avatar asked Feb 22 '23 09:02

Gnijuohz


1 Answers

I know assembly is efficient because it has a close relation to machine language.

No, it does not. it has a 1.1 relation - it is a written representation of exact machine code commands. It is a mnemonic language - basically replacing byte codes with another representation. All higher langauges miss that.

But c and c++ or ruby,let say,they are all gonna be 'translated' into machine language,right?

Yes, but the question is when and how efficient. low level languages - and C is one - allow less advanced constructs and are thus closer to assembler and easier for the compiler to optimize.

By more efficient,does it mean the machine code is better,or it takes less time to be 'translated' into machine code?

Outside of just in time compiled languages or interpreters NOONE cares about how much time it takes to translate. C is statically translated, once, then executed.

What if there is some compiler or interpreter that can produce faster,with better machine code?

Then the statement is not true. Funny enough, that is not really the case - it is not that easy to make a super efficient compiler for higher languages. Basically you keep asking why a super sports car is so fast & state it would not be considered to so fast anymore when every Fiat Panda would have more horsepower - but sadly they don't have and never will have.

like image 168
TomTom Avatar answered Feb 24 '23 00:02

TomTom