-8

In c++, does string.h header file contain only the decleration of the string functions?

If true, then where are they implemeted.

Harsha
  • 349
  • 1
  • 8
  • 20
  • search string.h in solution file (External Dependencies) you will be navigated to header file actually – Ali Kazmi Oct 15 '14 at 09:57
  • I found that it contains only the decleartion of the prototypes for the needed functions – Harsha Oct 15 '14 at 09:57
  • what else you need? Implementation? its implemented in string.cpp – Ali Kazmi Oct 15 '14 at 09:58
  • In a `string.cpp` file which is compiled to a library `(say x)`. Now your linker links your code with `x` to allow you to use functions declared in `string.h` – Ashwani Oct 15 '14 at 09:59
  • So, U Mean a default string.cpp, file exists with all the needed defination implemeted? – Harsha Oct 15 '14 at 10:04

3 Answers3

0

string.cpp

^Well, that's the only answer!

CinCout
  • 9,486
  • 12
  • 49
  • 67
0

You can find it out with man string, in which you could find it is a part of Standard C Library, as known as the libc library.

jsvisa
  • 2,987
  • 2
  • 24
  • 30
  • Thnku, So u mean for all standard functions, it refers to libc library during linking process – Harsha Oct 15 '14 at 10:21
  • It's true in some situation. those standard function will be linked during the program starting. – jsvisa Oct 15 '14 at 10:28
  • Thnk u, How does it know that for String functions it has to link with String library file, for math functions to link with math file, Is it based(Decided) on header file? – Harsha Oct 15 '14 at 10:40
0

Header files normally only contains prototype declarations of methods, just to satisfy initial compiler checks. The implementation files are already compiled to binary forms and distributed as library files. They are linked to your program during the linking process.

If you have studied C, you will remember that you used to add a prototype declaration of your custom method (which is defined below main() function) on top of the main() method. If not, you will get a compiler error. Header files contains these kinds of protocol declaration of methods that is defined in related cpp/c files, so that initial checks won't stop the compilation. Writing this way also helps to hide the implementation part of your software, but other users can use this method for their needs by seeing the protocol declaration.

You can get more information about the compiling linking process here.

To answer your question

In c++, does string.h header file contain only the decleration of the string functions?

Yes, they only contain declarations

If true, then where are they implemeted.

The related C++ files are compiled and distributed as library in binary format. On Unix systems it is in Standard C Library (libc)

Community
  • 1
  • 1
Krishnabhadra
  • 34,169
  • 30
  • 118
  • 167