Re: Sources for functions like malloc()

From: William Ahern (william_at_wilbur.25thandClement.com)
Date: 07/06/04


Date: Tue, 6 Jul 2004 11:48:47 -0700

Blue Ocean <blueoceanz1@hotmail.com> wrote:
> Hey all, I have another question. I may seem like a moron here, but
> where can I find out how C-standard functions like malloc() and
> printf() are declared? I know that I can find on my computer their .h
> files, but I can't find the .c files anywhere. Are they already in
> object code or something? Can I disassemble them to see how they are
> written?

Aside from the previous corrections and suggestions (a good book can be
invaluable), the OpenBSD sources (and I'm sure NetBSD) are pretty clean-cut:

        http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/

If you dive into GCC or glibc you might drown. You can get lost in the
assembly, I18N, SYSV & POSIX.2 & BSD emulation, Linux'isms, etc.

Keep in mind that the internals of malloc(), printf() and the like can
differ widely; you can easily screw yourself by getting chummy w/ them. Keep
a copy of the ISO C standard at hand to stay afloat.

Even better than looking at other sources is trying to emulate the behavior
of the above w/o peeking at what others did. Seeing somebody's answers can
undermine your ability to truly understand the problem(s) and to be readily
able to imagine alternatives.



Relevant Pages

  • Sources for functions like malloc()
    ... I may seem like a moron here, ... where can I find out how C-standard functions like malloc() and ... printf() are declared? ...
    (comp.lang.c)
  • Re: Sources for functions like malloc()
    ... >> Hey all, I have another question. ... I may seem like a moron here, ... >> and printf() are declared? ... the OpenBSD sources are ...
    (comp.lang.c)
  • Re: malloc reentrant?
    ... > standard should be reentrant, malloc not among them. ... A significant consequence is that a signal handler that uses {printf, ...
    (comp.os.linux.development.apps)
  • Re: query about printf
    ... implementation of printf() that used a static internal buffer to build ... The buffer needn't be static; ... ever asynchronous events there could be) and the handler ... printfalso could call malloc() and when, ...
    (comp.lang.c)
  • Re: regarding free
    ... malloc is declared in. ... strcpy is declared in. ... printf if declared in. ... char *data; ...
    (comp.lang.c)