[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] How to handle builtin functions?

From: Joerg Wunsch
Subject: [avr-libc-dev] How to handle builtin functions?
Date: Mon, 2 Sep 2002 15:58:10 +0200
User-agent: Mutt/1.2.5i

I noticed <math.h> has the following:

extern double fabs(double) __ATTR_CONST__;
#if 0
/* fabs seems to be built in already */
extern inline double fabs( double __x )
  { double __res;
    __asm__ __volatile__ ("andi %D0,0x7F \n\t"
                : "=d" (__res) : "0" (__x) );
    return __res;

Surprisingly enough, when linking one of my projects, the linker
complained about an undefined reference to fabs().

So i investigated a bit.  It seems all the various *abs* functions are
indeed builtins for gcc.  Thus, the inline functions for abs() and
labs() in <stdlib.h> can go away as well.  However, the usual exposed
names for these functions are disabled when using -ffreestanding.
Using this option makes some sense for the AVR (we don't really have
an environment, so we have a freestanding implementation in the sense
of the C standard), e. g. it allows to use "void main(void)" which
quite makes some sense in our case (main() is not really supposed to
ever return).  Yet, i think we should provide those builtin functions
that are applicable even in the -ffreestanding case.

One option would be to always override all of the builtins we want
to use like this:

#define abs(x) __builtin_abs(x)
#define labs(x) __builtin_labs(x)
#define fabs(x) __builtin_fabs(x)

The other options would be to just declare those functions the
usual way, and then encapsulate the above redirect #defines into
#if !__STDC_HOSTED (which is set to 0 when using -ffreestanding).

J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]