LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-25-2014, 11:08 AM   #1
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Utilizing C libraries


Hi all. Being introduced to libraries in C which are very helpful, as C has been around for ages and pretty much everything at a low level that you can think to create has already been done and redone a million times.

So, my question is this: How do you search/know what is available to you in libraries? For example, I created a 'power()' function to raise a number to a power, which was already available to me in <math.h>.

What is the standard/common/preferred way of checking, searching or finding these functions in local libraries/packages before going out and creating your own?

Edit: While answering,. please understand that powers() is an example of one single function out of thousands. Think 'generally.'

Last edited by szboardstretcher; 11-25-2014 at 01:44 PM.
 
Old 11-25-2014, 11:40 AM   #2
genss
Member
 
Registered: Nov 2013
Posts: 741

Rep: Reputation: Disabled
you can read some documentation
or look/grep the headers

or nm -g /lib64/libm-2.20.so | grep pow

for mathematics things there are many, some optimized
things like BLAS/ATLAS, LAPACK, FFTW come to mind

you can also.. you know, ask

bdw
i think that writing your own function is good with mathematics

Last edited by genss; 11-25-2014 at 11:41 AM.
 
1 members found this post helpful.
Old 11-25-2014, 01:30 PM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by szboardstretcher View Post
So, my question is this: How do you search/know what is available to you in libraries? For example, I created a 'power()' function to raise a number to a power, which was already available to me in <math.h>.
The standard C library is small enough that you can remember it all.

Assuming I forgot that power() is available in the standard library: if I only need integer powers the obvious multiplying loop is simple enough that I would just use that directly (i.e. it's faster to use that than start looking up a library function for it). If I need real number powers then I'd have to look up the method to compute that; I would search for libraries at the same time to see which approach is going to be easier.
 
Old 11-25-2014, 01:30 PM   #4
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
You could grep the header files in /usr/include.
 
Old 11-25-2014, 01:50 PM   #5
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Original Poster
Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Quote:
Originally Posted by psionl0 View Post
You could grep the header files in /usr/include.
This seems to be the most straight-forward, assuming you know what the function is called.

Quote:
Originally Posted by ntubski View Post
The standard C library is small enough that you can remember it all.
That's true, upon inspection.

But there are millions of libraries. How do the professional C programmers keep from re-inventing the wheel constantly? Do they just download ALL the *-devel packages and grep through the header files for related functions, or do they go on a forum and ask about existing functions, or is there a central repository for them, or is there a wiki, or is there a secret IRC channel, or is there a handy programmers 'function finder' program, or a web based 'header crawler' that indexes them,..

No one is memorizing millions of headers and functions. But, there has to be some kind of known method to finding pre-made functions to implement them.

In any big project, there are hundreds of library dependencies. How do C people find and use those library dependencies?

Last edited by szboardstretcher; 11-25-2014 at 01:51 PM.
 
Old 11-25-2014, 01:55 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by szboardstretcher View Post
a web based 'header crawler' that indexes them,..
It's no use indexing "headers" specifically. If you don't know about the library you won't know the precise function name anyway.
Quote:
In any big project, there are hundreds of library dependencies. How do C people find and use those library dependencies?
A standard web search engine is usually pretty effective.
 
Old 11-25-2014, 02:16 PM   #7
genss
Member
 
Registered: Nov 2013
Posts: 741

Rep: Reputation: Disabled
Quote:
Originally Posted by szboardstretcher View Post
How do the professional C programmers keep from re-inventing the wheel constantly?
idk, ask toolkit devs
 
Old 11-26-2014, 01:10 PM   #8
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Original Poster
Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
http://linux.die.net/man/3/sleep

Which is kind of what I expected to exist.

You can get the same behavior locally with 'man' like this:

Code:
man 3 sleep
As it turns out the manual is broken into sections with the third(3) section having to do with library functions.

Last edited by szboardstretcher; 11-27-2014 at 01:14 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Utilizing /opt partition? dwmolyneux Gentoo 4 06-16-2012 02:14 AM
Am I utilizing my Quad Core? WhoFlungDo Linux - Enterprise 5 04-04-2012 09:27 PM
Fully utilizing your X-Core CPU bret381 Linux - Software 1 03-16-2010 08:14 AM
Rexec utilizing winbind mike.sheeran Linux - Server 2 09-30-2008 09:01 AM
Utilizing multiple WAPs ferreter Linux - Laptop and Netbook 4 03-06-2004 02:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration