Alex Rivera | Logout

Why there is no standard way to force inline in C++?

Asked 2011-05-24T09:35:17.590
21

According to the wikipedia C++ article

C++ is designed to give the programmer choice, even if this makes it possible for the programmer to choose incorrectly.

If it is designed this way why there is no standard way to force the compiler to inline something even if I might be wrong?

Or I can ask why is inline keyword is just a hint?

I think I have no choice here.

In the OOP world we call methods on the objects and directly accessing members should be avoided. If we can't force the accessors to be inlined, then we are unable to write high performance but still maintainable applications.

(I know many compilers implement their own way to force inlining but it's ugly. Using macros to make inline accessors on a class are ugly too.)

Does the compiler always do it better than the programmer?

Edit
Report

1 Answer

0

Mistaken assumption.

There is a way. It's spelled #define. And for many early C projects, that was good enough. inline was sufficiently different - hint, better semantics - that it could be added besides macros. But once you had both, there was little room left for a third option in between, one with the nicer semantics but non-optional.

answered 2011-05-24T12:27:12.780

Your Answer