[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] gcc binary
From: |
Dave Hansen |
Subject: |
Re: [avr-gcc-list] gcc binary |
Date: |
Wed, 03 Mar 2004 14:39:00 -0500 |
<x-flowed>
From: Joerg Wunsch <address@hidden>
[...]
As "E. Weddington" <address@hidden> wrote:
>Worse: its not even a part of the C language. It has nothing to do
>with GCC, or the AVR.
It seems to be quite common among µC C compilers. Unlike the PORTB.0
notation where I don't see how this would ever fit at all into legal C
syntax, I can imagine that 0b is a perferctly legal vendor extension
for a compiler.
I believe it was proposed for the C99 standard, but nobody pushed it
through.
Just curious, I've once made a patch for GCC that implements it. This
was merely intented to be a proof of concept. Does anyone
incidentally know whether this feature might have already been
proposed (and perhaps put down) to the GCC folks? If not, do people
feel I should submit that patch?
In case anyone is interested:
http://www.sax.de/~joerg/gcc-0b.patch
Tom Torfs posted the following preprocessor hack in comp.arch.embedded. I
haven't tried it yet, but it should work on a standard compiler.
Regards,
-=Dave
/* Binary constant generator macro
By Tom Torfs - donated to the public domain
*/
/* All macro's evaluate to compile-time constants */
/* *** helper macros *** /
/* turn a numeric literal into a hex constant
(avoids problems with leading zeroes)
8-bit constants max value 0x11111111, always fits in unsigned long
*/
#define HEX__(n) 0x##n##LU
/* 8-bit conversion function */
#define B8__(x) ((x&0x0000000FLU)?1:0) \
+((x&0x000000F0LU)?2:0) \
+((x&0x00000F00LU)?4:0) \
+((x&0x0000F000LU)?8:0) \
+((x&0x000F0000LU)?16:0) \
+((x&0x00F00000LU)?32:0) \
+((x&0x0F000000LU)?64:0) \
+((x&0xF0000000LU)?128:0)
/* *** user macros *** /
/* for upto 8-bit binary constants */
#define B8(d) ((unsigned char)B8__(HEX__(d)))
/* for upto 16-bit binary constants, MSB first */
#define B16(dmsb,dlsb) (((unsigned short)B8(dmsb)<<8) \
+ B8(dlsb))
/* for upto 32-bit binary constants, MSB first */
#define B32(dmsb,db2,db3,dlsb) (((unsigned long)B8(dmsb)<<24) \
+ ((unsigned long)B8(db2)<<16) \
+ ((unsigned long)B8(db3)<<8) \
+ B8(dlsb))
/* Sample usage:
B8(01010101) = 85
B16(10101010,01010101) = 43605
B32(10000000,11111111,10101010,01010101) = 2164238933
*/
_________________________________________________________________
Learn how to help protect your privacy and prevent fraud online at Tech
Hacks & Scams. http://special.msn.com/msnbc/techsafety.armx
_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list
</x-flowed>