You are not logged in.

#1 2012-02-01 17:24:30

nbtrap
Member
Registered: 2011-02-24
Posts: 110

[SOLVED] Where are standard library functions like getchar() defined?

I'm new to programming, and I'm curious about the definitions of standard library functions like getchar(), but when I look in stdio.h, all I see are function prototypes. Where is the actual definition? Is it built into the compiler?

Thanks for your help.

Last edited by nbtrap (2012-02-21 17:24:31)

Offline

#2 2012-02-01 17:40:28

KingX
Member
From: CA
Registered: 2010-03-24
Posts: 324

Re: [SOLVED] Where are standard library functions like getchar() defined?

That would be in stdio.c, stdio.h is the header file.

Offline

#3 2012-02-01 17:51:57

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [SOLVED] Where are standard library functions like getchar() defined?

Odds are you don't have stdio.c.  You will have stdio.so (or something similar) which is the compiled object file resulting from stdio.c.

Read up on linkers if you wish to learn more about this.  There was a great web-book linked in another recent discussion on the programming sub-forum specifically on compilers and linkers.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2012-02-01 18:01:54

nbtrap
Member
Registered: 2011-02-24
Posts: 110

Re: [SOLVED] Where are standard library functions like getchar() defined?

KingX wrote:

That would be in stdio.c, stdio.h is the header file.

Thank you, I think I understand now. Correct me if I'm wrong: stdio.c is source code for glibc, which is compiled into a shared object file that is distributed with the glibc package. My only question would then be: how does the compiler know to link to the object file when it's not explicitly stated. For example when I compile a program, why do I not have to type:

gcc program.c /usr/lib/libc.so

and why does

gcc program.c

suffice?

Offline

#5 2012-02-01 19:32:41

toofishes
Developer
From: Chicago, IL
Registered: 2006-06-06
Posts: 602
Website

Re: [SOLVED] Where are standard library functions like getchar() defined?

Everything always gets linked to libc implicitly, unless you tell it otherwise by using `-nostdlib`.

Offline

Board footer

Powered by FluxBB