Phil Kos writes:
>
> >As Alan says, the standard libc build already splits each C file into lots
> >of .o files, one per function, which are the bundlued into libc.a.
>
> Gee, I sure hope not... .c files should *never* turn into multiple .o files.
> Any .c should be converted by cc (cpp/cc1/as) into one and only one .o.
> Separate functions can generally (but not always*) be broken out into
> separate .c files, in which case they will become separate .o files.
>
>
Look at this fragment from string.c in libc:-
/********************** Function strncat ************************************/
#ifdef L_strncat
char * strncat(d, s, l)
char *d, *s;
size_t l;
{
register char *s1=d+strlen(d), *s2;
s2 = memchr(s, l, 0);
if( s2 )
memcpy(s1, s, s2-s+1);
else
{
memcpy(s1, s, l);
s1[l] = '\0';
}
return d;
}
#endif
/********************** Function strncpy ************************************/
#ifdef L_strncpy
char * strncpy(d, s, l) /* FIXME need the fast version of this */
char *d, *s;
size_t l;
{
register char *s1=d, *s2=s;
while(l > 0)
{
l--;
if( (*s1++ = *s2++) == '\0')
break;
}
/* This _is_ correct strncpy is supposed to zap */
for(; l>0; l--) *s1++ = '\0';
return d;
}
#endif
/********************** Function strncmp ************************************/
Each function is surrounded by an ifdef. The C file is compiled several
times, one for each function it contains, each time with a different thing
defined.
i.e.
bcc -c -o strncat.o -DL_strncat string.c
bcc -c -o strncpy.o -DL_strncpy string.c
Thus we end up with a whole load of object files from one C file, which can
then be linked to produce a more optimal binary. This is done by the
Makefile, not by the compiler.
Al