inlining

Bill Poser poser at csli.Stanford.EDU
Tue Oct 23 17:29:02 AEST 1990


To my knowledge, there is no way to determine at compile time whether
a particular function is actually being in-lined. Is that correct?
The discussion of fast string comparison made me think of this.
Suppose that we have a macro like Henry Spencer's STREQ:

#define STREQ(a,b) (*(a) == *(b) && strcmp((a),(b)) == 0)

Insofar as it is true that most comparisons fail on the first
character, this should speed things up over a simple call to strcmp.
However, that supposes that the call to strcmp is a real function call.
If strcmp is inlined, doing the extra comparison of the first characters
is likely to slow things down. This suggests that it would be nice to
be able to define STREQ differently depending on whether strcmp is
inlined, e.g.:

#if inlined(strcmp)
#define STREQ(a,b) strcmp((a),(b))
#else
#define STREQ(a,b) (*(a) == *(b) && strcmp((a),(b)) == 0)
#endif

						Bill Poser



More information about the Comp.lang.c mailing list