February 2023

S M T W T F S
   1234
567891011
12131415161718
19202122232425
262728    

Style Credit

Expand Cut Tags

No cut tags
Thursday, November 29th, 2007 12:07 pm
For the C/C++ geeks out there, here's a grumpymaking thing I stumbled upon today.

In a .h file:
void __inline FUNCTION_NAME(mystruct* foo)
{
   foo->addrValid = TRUE; 
}

And therefore, in my .c file:
// HORRIBLE HACK!  Only one .o in an executable can have StupidInclude.h included.
// It defines inline functions and the link step will fail if multiple .o files
// contain those definitions.  But every .o in this type of executable must have the
// app data structure definition... which, for this app, relies on StupidInclude.h.
// Therefore, there can be only one .o in this executable.
#include "echoer.c"
#include "listener.c"
#include "pinger.c"

I know there are ways around this, potentially involving (say) precompiled headers, but this is supposedly a simple proof-of-concept app so I'm not bothering for now. And seriously. Who would release something like that and not get fired? Never mind; I know the answer.
Friday, November 30th, 2007 06:30 am (UTC)
Maybe I am being stupid. But I am pretty sure that your problem is that this is not declared static. This works great for some not-particularly-pleasant functions like

static inline int64_t
atomic64_add(atomic64 *a, int64_t b)
{
    int64_t i;

    i = b;
    __asm__ __volatile__( LOCKPREFIX "xaddq %0, %1" : "+r" (b), "+m" (a->value) : : "memory");

    return (b + i);
}


Friday, November 30th, 2007 06:45 am (UTC)
That would be exactly my problem, yes. It's in a header file I cannot modify, and I sure do wish they had chosen to put that little word in there.

Brooks notes above that this is a GCC holdover from the days when __inline hadn't been standardized. Still, since GCC is by far the major compiler in use for this code, I wish the library vendor had TRIED it.
Friday, November 30th, 2007 07:20 am (UTC)
You can fix this problem without modifying the header file. Make a file, static_override.h or something, containing a line that redeclares the function properly, like so:

static inline void FUNCTION_NAME();

Now just make sure that you include static_override.h before you include the broken one.