Results 1 to 7 of 7

Thread: Two questions: GCC

  1. #1
    Join Date
    Jun 2008
    Location
    New York, USA
    Beans
    781

    Two questions: GCC

    Hi all!

    This is probably simple stuff... but I can't seem to find it (yes I googled the heck out of it).

    OK, Ques #1: In Linux and using GCC, how do I determine which library has the function I need?

    Ques #2: I need to do base 10 exponent (that is, 10^0=1, 10^1=10, 10^2=100, etc...) how do I do it in GCC?

    In Win LCC-32 there is a function "pow10()" which takes 1 parameter (the exponent). For example, "pow10(3) == 1000".

    Anything like this in GCC, or do I have to write my own?

    Thanks!

    -- Roger
    Gentlemen may prefer Blondes, but Real Men prefer Redheads!

  2. #2
    Join Date
    Apr 2005
    Location
    Glasgow, Scotland
    Beans
    1,642

    Re: Two questions: GCC

    First off, GCC is a C compiler. glibc is the GNU C Standard Library, which is what you meant by GCC.

    Quote Originally Posted by Krupski View Post
    OK, Ques #1: In Linux and using GCC, how do I determine which library has the function I need?
    You need to know what library a function is in before you can use it.

    Quote Originally Posted by Krupski View Post
    Ques #2: I need to do base 10 exponent (that is, 10^0=1, 10^1=10, 10^2=100, etc...) how do I do it in GCC?

    In Win LCC-32 there is a function "pow10()" which takes 1 parameter (the exponent). For example, "pow10(3) == 1000".

    Anything like this in GCC, or do I have to write my own?
    You're getting confused between GCC and glibc, see above.

    Anyway, glibc has the function pow10 (the documentation says that exp10 is preferred), which takes a double and returns a double. Include <math.h>, and add "-lm" to the GCC command.
    A Fedora user

  3. #3
    Join Date
    Jun 2008
    Location
    New York, USA
    Beans
    781

    Re: Two questions: GCC

    Quote Originally Posted by bruce89 View Post
    Anyway, glibc has the function pow10 (the documentation says that exp10 is preferred), which takes a double and returns a double. Include <math.h>, and add "-lm" to the GCC command.
    I have done both (include math.h and use the -lm switch) and here's what I get:

    Code:
    convert.c: In function ‘main’:
    convert.c:73: warning: implicit declaration of function ‘pow10’
    convert.c:73: warning: incompatible implicit declaration of built-in function ‘pow10’
    I get the same exact error with "exp10" - no difference.

    Concerning my first question, if I *didn't* know that "pow10()" needed "math.h", how would I go about finding which "include" to use?

    I saw the answer on here somewhere before... but I don't remember what it was and I can't find it.
    Gentlemen may prefer Blondes, but Real Men prefer Redheads!

  4. #4
    Join Date
    Aug 2007
    Location
    127.0.0.1
    Beans
    1,800
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Two questions: GCC

    Code:
    pow(10, 3);
    http://www.cplusplus.com/reference/clibrary/cmath/
    (Yeah, it's a c++ reference, but the C library is intact!)
    Last edited by Can+~; February 17th, 2009 at 03:36 AM.
    "Just in terms of allocation of time resources, religion is not very efficient. There's a lot more I could be doing on a Sunday morning."
    -Bill Gates

  5. #5
    Join Date
    Jun 2008
    Location
    New York, USA
    Beans
    781

    Re: Two questions: GCC

    Quote Originally Posted by Can+~ View Post
    Code:
    pow(10, 3);
    http://www.cplusplus.com/reference/clibrary/cmath/
    (Yeah, it's a c++ reference, but the C library is intact!)
    Well now that works! Thank you so much.

    -- Roger

    (edit to add): Thanks for the link to the reference too! It'll be a great help.
    Last edited by Krupski; February 17th, 2009 at 05:33 AM.
    Gentlemen may prefer Blondes, but Real Men prefer Redheads!

  6. #6
    Join Date
    May 2007
    Beans
    251

    Re: Two questions: GCC

    Quote Originally Posted by Krupski View Post
    Concerning my first question, if I *didn't* know that "pow10()" needed "math.h", how would I go about finding which "include" to use?

    I saw the answer on here somewhere before... but I don't remember what it was and I can't find it.
    You generally use manual pages to see how to use the function - what headers to include and what libraries to link to.
    For example, all the glibc functions are documented in the 3rd section of manual pages. So, you could do:
    Code:
    man 3 pow
    You need to have the 'manpages' package installed for that.
    The Unforgiven

  7. #7
    Join Date
    Jun 2008
    Location
    New York, USA
    Beans
    781

    Re: Two questions: GCC

    Quote Originally Posted by the_unforgiven View Post
    You generally use manual pages to see how to use the function - what headers to include and what libraries to link to.
    For example, all the glibc functions are documented in the 3rd section of manual pages. So, you could do:
    Code:
    man 3 pow
    You need to have the 'manpages' package installed for that.
    Thank you for the info. I'll have to install the manpages package... don't have it yet.

    Thanks!

    -- Roger
    Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •