Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » AVR-GCC
  • » [avr-libc-dev] Re: [avr-gcc-list] Poll: Who uses itoa() & cowith base != {2, 8, 10, 16}? [RSS Feed]

#1 Nov. 19, 2005 11:59:39

Jörgen B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-libc-dev] Re: [avr-gcc-list] Poll: Who uses itoa() & cowith base != {2, 8, 10, 16}?


Can it be automated by the compiler?

I'm thinking something like:

inline itoa(int i,char* p,int base)
{
if (some_magic_gcc_macro_is_constant_parameter(base))
{
if (base==2)
{
itoa_base2(i,p);
}
else if (base == 10)
{
itoa_base10(i,p);
}
}
else {
itoa_full(i,p);
}
}

So if you call itoa(i,p,2) it will have only link to itoa_base2.----- Original Message -----From: "Daniel O'Connor" <>To: <avr-gcc-l***@*ongnu.org>
Cc: <avr-libc-***@*ongnu.org>
Sent: Saturday, November 19, 2005 11:26 AMSubject: Re: Re: Poll: Who uses itoa() &cowith base != {2, 8, 10, 16}?_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-l***@*ongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#2 Nov. 19, 2005 19:19:55

Joerg W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-libc-dev] Re: [avr-gcc-list] Poll: Who uses itoa() & cowith base != {2, 8, 10, 16}?


As Jörgen Birkler wrote:

> Can it be automated by the compiler?
>
> I'm thinking something like:
>
> inline itoa(int i,char* p,int base)
> {
> if (some_magic_gcc_macro_is_constant_parameter(base))
> {
> if (base==2)
> {
> itoa_base2(i,p);
> }
> else if (base == 10)
> {
> itoa_base10(i,p);
> }
> }
> else {
> itoa_full(i,p);
> }
> }

I'll keep that idea in mind. It might really be possible to do it,
but of course, this will all fail (and then pull in the full and slow
version) if the base value is not a compile-time constant even in
situations where base is one out of {2, 8, 10, 16}, so the fast
version would be sufficient.

--
cheers, J"org .-.-. --... ...-- -.. . DL8DTLhttp://www.sax.de/~joerg/NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#3 Nov. 22, 2005 03:13:55

Colin O.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-libc-dev] Re: [avr-gcc-list] Poll: Who uses itoa() & cowith base != {2, 8, 10, 16}?


Hey,

>if the base value is not a compile-time constant

I'd imagine in most situations the value would be a constant. And IMHO it
fails more "gracefully" - you end up with a situations where the end result
is more code usage.

In the other case you end up with a broken function if the user does not
realize they need to specify the full version. Imagine if you were using
non-standard bases and assumed that the itoa function was working and you're
trying to debug your system...

Warm Regards,

-Colin


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

  • Root
  • » AVR-GCC
  • » [avr-libc-dev] Re: [avr-gcc-list] Poll: Who uses itoa() & cowith base != {2, 8, 10, 16}? [RSS Feed]

Board footer

Moderator control

Enjoy the 22nd of January
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support