l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2004 Oct 25 12:17

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] C99 functions - what does "type generic" really mean?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] C99 functions - what does "type generic" really mean?

On Sunday 24 October 2004 08:56, Peter Jay Salzman wrote:
> I'm trying to get one of my programs to compile and run on a 64bit alpha
> running Debian/unstable.
> gcc is generating "implicit declaration" errors (I'm using -Werror) for
> functions like ceill(), sqrtl(), logl(), etc.
> I always took <tgmath.h> to be declarations for math functions that work on
> any kind of data type, like a sqrt that returns a long double (named sqrtl)
> or a ceil that returns a float (named ceilf).
> But upon a little reading, I think I might be incorrect.
> Is the point of tgmath to allow us to use sqrt() for ANY floating point
> type and the compiler will take care of the details of calling the proper
> version of the function?
> If so, the compiler can certainly guess which math function we want to use,
> but in the snippet:
>    long double ret;
>    float arg;
>    ret = sqrt(arg);
> would the compiler choose sqrtl() or sqrtf() as the backend to sqrt()?
It would choose sqrtf. tgmath.h defines sqrt as a macro so the type it chooses
will depend on its args. The result will be cast to the type of "ret", if that
is valid, otherwise there will be an error.
> Or was I originally correct in thinking that it's up to us to invoke which
> function we want explicitly, like:
>    long double ret;
>    long double arg;
>    ret = sqrtl(arg);
Since sqrtl is not a macro no substitution will occur and you will get exactly
what you coded. tgmath.h does include math.h (and complx.h)

Richard Harke

vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!