Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ code which is slower than its C equivalent? [closed]

Are there any aspects to the C++ programming language where the code is known to be slower than the equivalent C language? Obviously this would be excluding the OO features like virtual functions and vtable features etc.

I am wondering whether, when you are programming in a latency-critical area (and you aren't worried about OO features) whether you could stick with basic C++ or would C be better?

like image 420
user997112 Avatar asked Dec 09 '22 21:12

user997112


1 Answers

Nothing in the C or C++ language standards specifies the speed of any construct (C++ does specify the time complexity of some operations applied to containers, but that's outside the scope of your question). The speed of the code generated for a given construct depends on the compiler used to compile it, and on the system it runs on.

For a given code construct that's valid C and valid C++ with the same semantics, there's no fundamental reason why either should be faster than the other. But it's likely that one will be faster than the other if the developers of the compiler were a little more clever.

like image 98
Keith Thompson Avatar answered Dec 27 '22 00:12

Keith Thompson