how to add our own function in c library please give details.?



how to add our own function in c library please give details.?..

Answer / sevak.yatrik777

There are a few ways to do this.

Write the code with a proper header file and compile to an
object file. You only need to include the header in your
code and tell the compiler where to find the object file. In
most cases, you can combine functions in object files to
create a larger library object file. Note that once you
compile to an object file, it may also be included for use
with other compiled programming languages. You can do this
with some Microsoft compilers and some Gnu based compilers
under Linux but you can't mix Gnu and Microsoft. You could
mix Quick BASIC and Microsoft C, Some versions of Visual
Basic and Visual C/C++, Basic/Pascal/Delphi/C/C++, and gcc
and other gcc based languages if the languages have the
extras to deal with alternate styles of passing arguments as
needed. You may need to include something like CDECL for
declaring functions in other languages. This can be a
multiple step process if you are compiling using more than
one programming language.

A second option is write your code with a proper header
file. Copy the library code to the work directory for the
project and compile as you would for any other multiple file
project. This assumes you are only using compatible C or C++
compilers.

A third option is you compile the library to object code
using the compiler for the project. This is common practice
for special math libraries and other library packages. You
only need to include header files and the location of the
object files in your main project like in option 1 though it
is more or less option 2 done in two steps. Many of the free
libraries are available this way.

I generally go with the second or third option as I use
several compilers and if it is a serious project, I'm
usually using C or C++ anyway. Some of my "library" files
contain special defines so they actually work with alternate
compilers. With a bit of research, you can often auto detect
the compiler from internal compiler specific defines. While
auto detcting compilers is a bit of extra work, your library
functions are virtually drop in and don't require any extra
work when you use them.

In the end, do what ever is best for your own projects.

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Interview Questions

What is the most efficient way to count the number of bits which are set in an integer?

0 Answers  


write a function to swap an array a[5] elements like a[0] as a[5],a[1] as a[4],....a[5] as a[0].without using more than one loop and use one array not to use temp array?

1 Answers   Zensar,


write the program for prime numbers?

73 Answers   Accenture, Aptech, Infosys, TCS,


what would be the output of the follwing struct st { char name[20]; int i; float f; }; main() { struct st emp = {"forum"}; printf("%d %f",emp.i,emp.f); }

4 Answers  


Do array subscripts always start with zero?

0 Answers  






What are the 5 types of inheritance in c ++?

0 Answers  


program to locate string with in a string with using strstr function

2 Answers   Huawei, Shreyas,


what are the advantages of a macro over a function?

0 Answers   TCS,


which will be first in c compiling ,linking or compiling ,debugging.

3 Answers   Sonata,


a c code by using memory allocation for add ,multiply of sprase matrixes

0 Answers  


How macro execution is faster than function ?

0 Answers   Wipro,


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

1 Answers  


Categories