Re: How to get started down the path...
walt wrote:
>
> On Fri, 11 Feb 2005, Max Okumoto wrote:
>
>
>> 2.3 Write stub functions for thing you don't want to
>> bring in.
>
>
> Great post, Max, thanks! I've seen 'stub' used often when
> talking about libraries, but I've never really understood
> what it means. Could you give me a concrete example of
> what a stub is and why I might want to use one?
A stub function is a function with the same signature
as the 'real' function. For instance libc contains a
function called syslog(). A stub function for syslog
would take the same parameters types, and return the
same type.
int
syslog(int type, char *bufp, int len)
{
/* no code is here */
assert(0); /* please impliment me! */
return 0; /* bogus return value */
}
The reason you write stub functions is that you don't
have the code to impliment the the functionality, but
you need the function to compile the code.
This might be the case if you were moving an application
that used syslog to an embeded system, that didn't have
syslogd running nor the library function for syslog().
Max
討論串 (同標題文章)
完整討論串 (本文為第 3 之 3 篇):