1

I want to see the "real" C source code of the functions — its real implementation in the gcc and clang compiler. I mean "real" because I look at in the header file but I see only a prototype and something that seems like an extension.

For example, let's say that I want the code of the standard C tmpnam() function. It's defined in the stdio.h header (by standard — I know that only its prototype must be defined there; the code itself can come from any (better chosen by the compiler writer) header file). But what I can see only is

/* Generate a temporary filename.  */
extern char *tmpnam (char *__s) __THROW __wur;
__END_NAMESPACE_STD

Where is the code of the function that make it work? That's I'm looking for. Similarly, I don't find it in the clang compiler. If possible, can someone explain why the compiler writer choose this model? Doesn't it leave the code explicit in the respective header file? Is it some "trick" to perform some type of optimization, or something like that?

2
  • What operating system are you using? Commented Jan 22, 2013 at 3:29
  • I'm on GNU/Linux OpenSUSE OS Commented Jan 22, 2013 at 4:11

1 Answer 1

4

You can try to get the source code of glibc or any similar C library implementation. That should have the code you are looking for. You can also browse the source code of glibc online.

As for the reasoning, its basic "You dont see what you dont need to see" reasoning. There is no need to see the implementation, just the interface to the library.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. I checked the online version,but where is the non-standard functions such as mktemp()?
@Jack If they are non standard, you need to look up which library they are coming from and track that down. Or it is possible they are also implemented by glibc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.