Inline functions
-
I've just found this in some code I've been given to maintain:
inline char * _fstrchr(const char *szStr, char ch)
{
return strchr(szStr, ch);
}It's in a .h file, and it's used all over the place. Is there any benefit with this function over using
strchr
directly? I thought inlined functions basic replaced the_fstrchr
token with the content of the function - as the function is not doing anything else, is there any point?
- Dy
-
I've just found this in some code I've been given to maintain:
inline char * _fstrchr(const char *szStr, char ch)
{
return strchr(szStr, ch);
}It's in a .h file, and it's used all over the place. Is there any benefit with this function over using
strchr
directly? I thought inlined functions basic replaced the_fstrchr
token with the content of the function - as the function is not doing anything else, is there any point?
- Dy
-Dy wrote:
thought inlined functions basic replaced the _fstrchr token
He used this token,
_fstrchr
, in the entire source. There's a benefit from this way: Some time later when there is a need to alter the implementation, he only needs to modify one line, instead of using the text search function to find out all the occurrences ofstrchr
. Similar concept as:#ifdef UNICODE #define _tcscpy strcpyW #else #define _tcscpy strcpyA #endif
Maxwell Chen