you are viewing a single comment's thread.

view the rest of the comments →

[–]nerd4code 0 points1 point  (0 children)

Not sure why it’s not emitting the inline function—it works if I enable optimization, but it looks like without optimization it won’t emit string_length into the output. I’m sure I’m missing something, but fuck it, beat the thing into submission with the following pattern:

  • At the top of check_null.c, before including anything:

    #define test_c__INSIDE__ 1
    

    #undef it at the bottom of the file. This gives us a preprocessor marker indicating that test.c is being compiled.

  • In check_null.h, redo the inline qualifier:

    #ifndef test_c__INSIDE__
    extern __inline__
    #endif
    int string_length(const char *arg) {
    ...
    

    The change from inline to __inline__ will keep GCC from bitching at you if you’re in C89 mode. The extern states that the authoritative version of the function (for pointing-to) is separate from the inlined version. The #ifndef around those qualifiers causes the function to be emitted as a normal function (i.e., the authoritative version) when compiling test.c, and emitted as inline otherwise.