naseeam
asked on
Macro to put data in Little Endian
My enivroment is Unix, C. I get the following compile error on attached 'C' code. Please advise.
"put_little_u32.c", line 8: error 4068: Missing comma seperator between par
ameters in macro "endian_put_native_to_litt le_u32".
"put_little_u32.c", line 8: error 4068: Missing comma seperator between par
ameters in macro "endian_put_native_to_litt
#include <stdio.h>
/* This macro reverses data order so LSB is first. */
#define endian_put_native_to_little_u32(long src, char * dest) \
dest[0] = (char)(src); \
dest[1] = (char)(src >> 8); \
dest[2] = (char)(src >> 16); \
dest[3] = (char)(src >> 24); /* line 8 */
main()
{
char data[4];
long pgn = 0x33221100;
endian_put_native_to_little_u32(pgn, &data[0]);
printf("data[0] = %d.\n", data[0]);
printf("data[1] = %d.\n", data[1]);
printf("data[2] = %d.\n", data[2]);
printf("data[3] = %d.\n", data[3]);
}
does it work?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Maybe you are looking for htonl or ntohl ?
Regards
Friedrich
Regards
Friedrich
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also, if you pass &data[0] rather than data
&data[0][1] would be parsed as &(data[0][1])
and taking [0][1] of a char[4] makes no sense, so it has to be
(&data[0])[1]
&data[0][1] would be parsed as &(data[0][1])
and taking [0][1] of a char[4] makes no sense, so it has to be
(&data[0])[1]
ASKER
Expert Fixed my source code. As a result my code compiled.
endian_put_native_to_littl