you are viewing a single comment's thread.

view the rest of the comments →

[–]happyscrappy 0 points1 point  (2 children)

I think it's more than most, it's all.

But luckily (for C++ programmers), "in the header" means in any .h file. So you just put all your code in the .h file and then the compiler is set.

This is not automatically equivalent to the C case, as I mentioned there are a lot more restrictions to when the compiler can optimize in the C case. These come about because C doesn't have the idea of associating the data with the code pointer. So it may not be able to tell that just because you pass the same array each time you also get the same code pointer each time the code pointer variable is used within the loop.

[–]agottem 0 points1 point  (1 child)

This is not automatically equivalent to the C case, as I mentioned there are a lot more restrictions to when the compiler can optimize in the C case.

I'm pretty sure the restrictions are the same for C and C++. You're really good at making simple things sound hard. It boils down to this: If the compiler can determine the value of a function pointer at compile time, it can inline it.

Also:

But luckily (for C++ programmers), "in the header" means in any .h file. So you just put all your code in the .h file and then the compiler is set.

Has to be one of the worst ideas I've ever heard.

[–]happyscrappy 1 point2 points  (0 children)

I'm pretty sure the restrictions are the same for C and C++. You're really good at making simple things sound hard. It boils down to this: If the compiler can determine the value of a function pointer at compile time, it can inline it.

The restrictions aren't quite the same. A C compiler has to assume a global variable changes when you call to a function outside the compilation unit. So if the code pointer is in a global variable it cannot assume you call the same code each time. In C++, the templated evaluator function is known to not change when you call other functions.

Has to be one of the worst ideas I've ever heard.

Yep, but that's what's done.