Andre <> wrote:
> I would like to handle a table of 4-byte long strings by just declaring
> them as an array of unsigned 32 bit values.
> Of course, this can be done manually, but it would be great if a macro
> XY existed, that, for example, from
> XY("ABCD") would generate a unsigned 32bit declaration like 0x41424344
Not sure what you mean by "declaration" here but perhaps some-
thing like this is what you're looking for
#include <stdio.h>
#include <stdint.h>
#define XY( x ) ( x[0] << 24 | x[1] << 16 | x[2] << 8 | x[3] )
int main( void )
{
uint32_t x = XY( "ABCD" );
printf( "0x%08x\n", x );
return 0;
}
Of course, the normal caveats apply, i.e. your relying on a
certain character encoding, that a char has 8 bits etc. And
that the macro argument is really something that is a pointer
to an array-like object with at least four chars.
Regards, Jens
--
\ Jens Thoms Toerring ___
\__________________________
http://toerring.de