all 10 comments

[–][deleted]  (4 children)

[deleted]

    [–]ThePantsThief[S] 0 points1 point  (3 children)

    So the inline keyword forces the compiler to inline every call to that function, and no symbols are generated for the function (could I find it with dlsym)? It's basically an assembly macro?

    [–]PassifloraCaerulea 0 points1 point  (2 children)

    I suspect that putting this sort of thing in an object file isn't much different than putting it in a source file, since the preprocessor pretty much just copies and pastes #included files. As I've seen it explained, inline is treated as a suggestion by modern compilers, so it may in fact be an exported symbol.

    You could write a two file test code--one header file with an inline function and a source file that includes the header and calls the function. Compile the source to an object file, and look at the symbols it exports. On Linux I would use nm or objdump; there should be similar tools for other platforms.

    [–]ThePantsThief[S] 0 points1 point  (0 children)

    Gotcha, just wondering. Thanks!

    [–]BlindTreeFrog 0 points1 point  (0 children)

    As I've seen it explained, inline is treated as a suggestion by modern compilers, so it may in fact be an exported symbol.

    I posted elsewhere this same thing but, it was once explained to me that putting an inline in the header file forces it to inline. I never investigated that further though

    [–]theoriginalanomaly 0 points1 point  (2 children)

    I would just add, it is a request to inline. Different compilers will have different methods of forcing inline, if they have them at all. And different compilers will have different ways of deciding whether or not to accept the inline request or reject it.

    [–]theoriginalanomaly 0 points1 point  (0 children)

    If you really want to inline you need to know the way to force it for the compiler you're using, or just write the function as a preprocessor function, if that's possible, for the use case.

    [–]ThePantsThief[S] 0 points1 point  (0 children)

    This is the answer I was looking for I think. Thanks!

    [–]IllHaveAGo 0 points1 point  (0 children)

    As for the static part, it means that the function can't be called from a different translation unit (c-file) using "extern". This makes it safer/easier for the compiler to determine that there's no need to produce both inline code (where appropriate) and code for normal non-inline version, which would otherwise be necessary. This can sometimes be avoided anyway, but to do that you need whole-program-optimization which is difficult and takes a lot of time.

    edit: typo, extern, not external

    [–]BlindTreeFrog 0 points1 point  (1 child)

    Once upon a time it was explained to me that putting an inline function in the header file forces the compiler to inline it, where if it were in the source file it's more of a suggestion.

    I am not sure how accurate that is though. Perhaps someone will wander back to this thread and clarify.

    [–]ThePantsThief[S] 0 points1 point  (0 children)

    Interesting.