473,657 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

lgamma function: ANSI C or not?

I'm having a .c source file which at the top contains the line

#include <math.h>

In that source file, i declare a function dt which in its body uses
the lgamma function. `man lgamma' on my linux system tells me
that i have to include math.h so it seems like I'm doing the
right thing in order to be able to use the lgamma function.

When I compile the .c file with

$ gcc -ansi -c rand.c

or

$ gcc -Wall -c rand.c

then I get no errors or warnings. When I compile it with

$ gcc -Wall -ansi -c rand.c

I get the warning:

rand.c: In function `dt':
rand.c:544: warning: implicit declaration of function `lgamma'

which seems strange to me. Why am I getting this warning and how do I
resolve this warning? I assume it has something to do with ANSI C or not,
but I'm confused...

Thanks,
Bart

PS: the version of gcc I'm using is gcc (GCC) 3.3.5 (Debian 1:3.3.5-13).
Upgrading to a newer version is no option because I do not have admin rights
to install or upgrade packages on my system.

--
"Share what you know. Learn what you don't."
May 10 '06 #1
15 2947

Bart Vandewoestyne wrote:
I'm having a .c source file which at the top contains the line

#include <math.h>

In that source file, i declare a function dt which in its body uses
the lgamma function. `man lgamma' on my linux system tells me
that i have to include math.h so it seems like I'm doing the
right thing in order to be able to use the lgamma function.

When I compile the .c file with

$ gcc -ansi -c rand.c

or

$ gcc -Wall -c rand.c

then I get no errors or warnings. When I compile it with

$ gcc -Wall -ansi -c rand.c

I get the warning:

rand.c: In function `dt':
rand.c:544: warning: implicit declaration of function `lgamma'

which seems strange to me. Why am I getting this warning and how do I
resolve this warning? I assume it has something to do with ANSI C or not,
but I'm confused...

Thanks,
Bart

PS: the version of gcc I'm using is gcc (GCC) 3.3.5 (Debian 1:3.3.5-13).
Upgrading to a newer version is no option because I do not have admin rights
to install or upgrade packages on my system.


Function `lgamma()` is only available in C99. GCC `-ansi` assumes C89
(same as `-std=c89`). Therein lies your problem. Have you tried
`-std=c99` instead?

May 10 '06 #2
"Bart Vandewoestyne" <My************ ********@telene t.be> wrote in message
news:11******** *******@seven.k ulnet.kuleuven. ac.be...
I'm having a .c source file which at the top contains the line

#include <math.h>

In that source file, i declare a function dt which in its body uses
the lgamma function. `man lgamma' on my linux system tells me
that i have to include math.h so it seems like I'm doing the
right thing in order to be able to use the lgamma function.

When I compile the .c file with

$ gcc -ansi -c rand.c

or

$ gcc -Wall -c rand.c

then I get no errors or warnings. When I compile it with

$ gcc -Wall -ansi -c rand.c

I get the warning:

rand.c: In function `dt':
rand.c:544: warning: implicit declaration of function `lgamma'

which seems strange to me. Why am I getting this warning and how do I
resolve this warning? I assume it has something to do with ANSI C or not,
but I'm confused...


lgamma is required by C99 and the Single Unix Specification
(effectively Posix). It is found in some older math libraries,
but not all.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
May 10 '06 #3
On 2006-05-09, Vladimir Oka <no****@btopenw orld.com> wrote:

Function `lgamma()` is only available in C99. GCC `-ansi` assumes C89
(same as `-std=c89`). Therein lies your problem. Have you tried
`-std=c99` instead?


Indeed: this doesn't generate warnings:

$ gcc -Wall -std=c99 -c rand.c

This does:

$ gcc -Wall -std=c89 -c rand.c
rand.c: In function `dt':
rand.c:545: warning: implicit declaration of function `lgamma'
So my options are:

* implement lgamma myself if i want to be c89 compatible
* don't try to be c89 compatible and compile with -std=c99

Thanks!
Bart

--
"Share what you know. Learn what you don't."
May 10 '06 #4
Bart Vandewoestyne wrote:
I'm having a .c source file which at the top contains the line

#include <math.h>

In that source file, i declare a function dt which in its body uses
the lgamma function. `man lgamma' on my linux system tells me
that i have to include math.h so it seems like I'm doing the
right thing in order to be able to use the lgamma function.
Yes you are.
When I compile the .c file with

$ gcc -ansi -c rand.c

or

$ gcc -Wall -c rand.c

then I get no errors or warnings. When I compile it with

$ gcc -Wall -ansi -c rand.c

I get the warning:

rand.c: In function `dt':
rand.c:544: warning: implicit declaration of function `lgamma'

which seems strange to me. Why am I getting this warning and how do I
resolve this warning? I assume it has something to do with ANSI C or not,
but I'm confused...


Yes and no. It was not part of the original ANSI standard but it is part
of the latest C standard known colloquially as C99. See
http://clc-wiki.net/wiki/c_standard for more about the various versions
of the C standard.

<OT>
With gcc you could try using -std=c99 instead of -ansi, however you
should be aware that gcc does not fully implement C99.

My man page for lgamma included
| CONFORMING TO
| C99, SVID 3, BSD 4.3

which tells you that it is C99 and which other standard provided it as
an extension to C.
</OT>

If you need further help on getting gcc to recognise the lgamma function
gnu.gcc.help could be useful.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
May 10 '06 #5
Bart Vandewoestyne wrote:
On 2006-05-09, Vladimir Oka <no****@btopenw orld.com> wrote:
Function `lgamma()` is only available in C99. GCC `-ansi` assumes C89
(same as `-std=c89`). Therein lies your problem. Have you tried
`-std=c99` instead?


Indeed: this doesn't generate warnings:

$ gcc -Wall -std=c99 -c rand.c

This does:

$ gcc -Wall -std=c89 -c rand.c
rand.c: In function `dt':
rand.c:545: warning: implicit declaration of function `lgamma'
So my options are:

* implement lgamma myself if i want to be c89 compatible
* don't try to be c89 compatible and compile with -std=c99

or, you could edit <math.h> and remove the c99 guard on math functions
you consider eligible for c89 compatibility.
May 10 '06 #6
Bart Vandewoestyne wrote:
On 2006-05-09, Vladimir Oka <no****@btopenw orld.com> wrote:
Function `lgamma()` is only available in C99. GCC `-ansi` assumes C89
(same as `-std=c89`). Therein lies your problem. Have you tried
`-std=c99` instead?


Indeed: this doesn't generate warnings:

$ gcc -Wall -std=c99 -c rand.c

This does:

$ gcc -Wall -std=c89 -c rand.c
rand.c: In function `dt':
rand.c:545: warning: implicit declaration of function `lgamma'
So my options are:

* implement lgamma myself if i want to be c89 compatible
* don't try to be c89 compatible and compile with -std=c99


If you chose to implement it yourself then I would strongly suggest
using a different name. That way you avoid confusion.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 10 '06 #7
Ico
Bart Vandewoestyne <My************ ********@telene t.be> wrote:
I'm having a .c source file which at the top contains the line

#include <math.h>

In that source file, i declare a function dt which in its body uses
the lgamma function. `man lgamma' on my linux system tells me
that i have to include math.h so it seems like I'm doing the
right thing in order to be able to use the lgamma function.

When I compile the .c file with

$ gcc -ansi -c rand.c

or

$ gcc -Wall -c rand.c

then I get no errors or warnings. When I compile it with

$ gcc -Wall -ansi -c rand.c

I get the warning:

rand.c: In function `dt':
rand.c:544: warning: implicit declaration of function `lgamma'

which seems strange to me. Why am I getting this warning and how do I
resolve this warning? I assume it has something to do with ANSI C or not,
but I'm confused...

The manpages also have information on conformaing standards: look a bit
further down in the same manpage :

CONFORMING TO
C99, SVID 3, 4.3BSD

As you can see, ANSI is not in the list
--
:wq
^X^Cy^K^X^C^C^C ^C
May 10 '06 #8
Tim Prince wrote:
Bart Vandewoestyne wrote:
On 2006-05-09, Vladimir Oka <no****@btopenw orld.com> wrote:
Function `lgamma()` is only available in C99. GCC `-ansi` assumes C89
(same as `-std=c89`). Therein lies your problem. Have you tried
`-std=c99` instead?


Indeed: this doesn't generate warnings:

$ gcc -Wall -std=c99 -c rand.c

This does:

$ gcc -Wall -std=c89 -c rand.c
rand.c: In function `dt':
rand.c:545: warning: implicit declaration of function `lgamma'
So my options are:

* implement lgamma myself if i want to be c89 compatible
* don't try to be c89 compatible and compile with -std=c99

or, you could edit <math.h> and remove the c99 guard on math functions
you consider eligible for c89 compatibility.


This is probably a bad idea for several reasons. It could break valid
C89 code (e.g. code that defines an lgamma function with a different
prototype) which you might not hit until months or years later, the C99
stuff may depend on compiler support which is only enabled when C99
support is enabled, it may depend on things in other headers that are
only enabled when C99 is enabled etc. Also the OP does not have admin
writes so probably can't do this anyway.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 10 '06 #9
"Flash Gordon" <sp**@flash-gordon.me.uk> wrote in message
news:ko******** ****@news.flash-gordon.me.uk...
Tim Prince wrote:
Bart Vandewoestyne wrote:
On 2006-05-09, Vladimir Oka <no****@btopenw orld.com> wrote:
Function `lgamma()` is only available in C99. GCC `-ansi` assumes C89
(same as `-std=c89`). Therein lies your problem. Have you tried
`-std=c99` instead?

Indeed: this doesn't generate warnings:

$ gcc -Wall -std=c99 -c rand.c

This does:

$ gcc -Wall -std=c89 -c rand.c
rand.c: In function `dt':
rand.c:545: warning: implicit declaration of function `lgamma'
So my options are:

* implement lgamma myself if i want to be c89 compatible
* don't try to be c89 compatible and compile with -std=c99

or, you could edit <math.h> and remove the c99 guard on math functions
you consider eligible for c89 compatibility.


This is probably a bad idea for several reasons. It could break valid C89
code (e.g. code that defines an lgamma function with a different
prototype) which you might not hit until months or years later, the C99
stuff may depend on compiler support which is only enabled when C99
support is enabled, it may depend on things in other headers that are only
enabled when C99 is enabled etc. Also the OP does not have admin writes so
probably can't do this anyway.


Most of those reasons are pretty esoteric, and not likely to matter
in real life. Nevertheless, I agree that it's a bad idea to edit
system headers. Besides, chances are all you have to do is put:

double (lgamma)(double );

at the top of the source file that calls the function. (The parens are
to protect the declaration against a macro override that may one day
come along.)

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
May 10 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2537
by: Gary Besta | last post by:
I am trying to add a simple case statement to a stored procedure or user defined function. However when I try and save the function/procedure I get 2 syntax errors. Running the query in query analyser works fine and a result is given with no syntax errors. I believe its something to do with the spaces in the field names. Not my choice as its an existing system I have to work around. Any help greatly appreciated SQL Query
25
3227
by: Java Böy | last post by:
could some body help me what's happening here... thanks.. char sc = "\x31\xc0" /* xor %eax, %eax */ "\x50" /* push %eax */ "\x68\x2f\x2f\x73\x68" /* push $0x68732f2f */ "\x68\x2f\x62\x69\x6e" /* push $0x6e69622f */ "\x89\xe3" /* mov %esp,%ebx */
2
1739
by: hykim | last post by:
I want to call a unmanaged dll's function returning some STRUCT's pointer. the next is definition of a STRUCT. ----------------------------------------------------------------------- typedef struct myStruct{ struct { UINT_PTR anything; UCHAR anything2; } myInnerStruct;
4
9905
by: Elephant | last post by:
Hello, The function Microsoft.VisualBasic.Chr( ), is there a similar function in System.Text ? How does this work? Thank you, me.
1
3266
by: Shawn | last post by:
As if it won't be clear enough from my code, I'm pretty new to C programming. This code is being compiled with an ANSI-C compatible compiler for a microcontroller. That part, I believe, will be irrelavent. My syntax is surely where I am going wrong. I'd like to be able to call this routine to read different values from another device. This routine would be called quite simply as follows: void main() {
6
2090
by: dndfan | last post by:
Hello, In the short time I have spent reading this newsgroup, I have seen this sort of declaration a few times: > int > func (string, number, structure) > char* string > int number > struct some_struct structure
5
2007
by: vicks | last post by:
Hi, I had just written the following code but not able to figure out why the sizeof() operator is printing the weired output when i give a function name as its operand? #include<stdio.h> #include <assert.h> int f();
8
2385
by: vaib | last post by:
hi all , It really seems that C never ceases to amaze . All this time i've been doing C and i thought i was quite adept at it but i was wrong . So without wasting any more time , here's the confusion . I read in K&R that ANSI introduced the concept of function prototyping in C and it was missing there initially ( it borrowed the concept from C++ ) _but_ it did it make it compulsory to actually include the function declaration in the...
3
2748
by: =?Utf-8?B?TWluZ3lp?= | last post by:
Hi, I have the following question regarding communicating with a OCX control using C#. Idon't have access to the ocx code, so my c# code is actually mimic the behavior of C++ counterparts. Basically, I have problem passing a structure to a function. Here is the C++ part code: //****************************************
0
8312
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8606
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4159
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.