Hacker News new | past | comments | ask | show | jobs | submit login

My (probably unpopular) opinion is that 'inline' should never have been added to the C standard, because it breaks the strict separation of interface declaration (in headers) and implementation code (in source files). Inline in C++ is the source of all sorts of problems, the biggest one being slow compilation because the same inline code in headers needs to be parsed over and over again.

Within the same compilation unit, the compiler will inline any suitable function anyway, and 'static' alone is enough to hint the compiler that there's no separate copy of the function needed if it can be inlined at all call sites.

And for inlining across compilation units, there's LTO these days (which admittedly wasn't a realistic option in the late 90's).




If you're putting an inline function into your header file, the size of the code for that function is part of the information provided by the interface (i.e. the inline code is getting stored with the user). Every user has to know they're duplicating that code locally.

I agree, though, that for the most part there are probably better ways to do it (including trusting in "the compiler is a better optimizer than my wetware").




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: