From owner-freebsd-questions@FreeBSD.ORG Tue Apr 11 23:07:37 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7A8D416A400 for ; Tue, 11 Apr 2006 23:07:37 +0000 (UTC) (envelope-from herriojr@gmail.com) Received: from nproxy.gmail.com (nproxy.gmail.com [64.233.182.191]) by mx1.FreeBSD.org (Postfix) with ESMTP id A748D43D58 for ; Tue, 11 Apr 2006 23:07:36 +0000 (GMT) (envelope-from herriojr@gmail.com) Received: by nproxy.gmail.com with SMTP id m18so981093nfc for ; Tue, 11 Apr 2006 16:07:35 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Rmj4OwGR7w3hdiiarzeCrn58bWzK9NJ4av2SmpjdsClsLM0wC/EpsllFO/fgyJv4G5vUggZr90CdCVAacPK6e8YyVwCYPZNP0r65SrggtJUFlgyjwY3GkWFU8SWVLaOijXkSuXhwwjPi4XlP5+mm3s0oUSOfhXoXJDt8yYgtrJ4= Received: by 10.49.10.15 with SMTP id n15mr1367978nfi; Tue, 11 Apr 2006 16:07:35 -0700 (PDT) Received: by 10.49.29.3 with HTTP; Tue, 11 Apr 2006 16:07:35 -0700 (PDT) Message-ID: <6a56d69c0604111607l5fba5939pfc6461a99a2ceab3@mail.gmail.com> Date: Tue, 11 Apr 2006 23:07:35 +0000 From: "Jonathan Herriott" To: "Nicolas Blais" In-Reply-To: <200604111857.43171.nb_root@videotron.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <6a56d69c0604111554o587ce2c5ha1ff4ea20bbab0a4@mail.gmail.com> <200604111857.43171.nb_root@videotron.ca> Cc: freebsd-questions@freebsd.org Subject: Re: pow function working unexpectedly X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Apr 2006 23:07:37 -0000 Question then. Why would it work when I don't use variables if I don't include the library? This question is just out of curiosity. On 4/11/06, Nicolas Blais wrote: > On Tuesday 11 April 2006 18:54, Jonathan Herriott wrote: > > I just want to make sure I'm not being stupid before I send in a bug. > > The problem seems to be with gcc when using the pow function in the > > math.h library. Here's code that works: > > > > #include > > #include > > > > int main() > > { > > printf("%f\n", pow(2,3)); > > return 0; > > } > > > > > > Now, the following will not compile: > > > > #include > > #include > > > > int main() > > { > > int x =3D 2; // I tried these as doubles too since the pow functio= n > > takes doubles > > int y =3D 3; > > > > printf("%f\n", pow(x,y)); > > return 0; > > } > > > > I compiled both programs using: > > gcc test.c > > > > The second example gives the following error: > > > > /var/tmp//ccxtkMwv.o(.text+0x45): In function `main': > > : undefined reference to `pow' > > > > If I comile with g++, I have no issues. Are these results that I > > should have? If so, why? If not, I'm going to submit the bug on gcc > > (or the linker, but I'm guessing it's the same group). > > > > Thanks, > > Jonathan Herriott > > gcc -lm test.c works. You forgot to include the math library. > > -- > FreeBSD 7.0-CURRENT #1: Sat Apr 8 21:33:25 EDT 2006 > root@clk01a:/usr/obj/usr/src/sys/CLK01A > PGP? : http://www.clkroot.net/security/nb_root.asc > >