[En-Nut-Discussion] H8/300 Question: Print Format Specifier For size_t
Jan Dubiec
jdx at slackware.pl
Wed Mar 17 19:28:44 CET 2004
On Wed, 17 Mar 2004 18:20:09 +0100, Harald Kipp <harald.kipp at egnite.de> wrote:
> In the H8 port, several format specifiers have been
> changed from %X to %lX.
>
> Example, found in app/httpserv.c
>
> #if defined(__AVR_ATmega128__) || defined(__AVR_ATmega103__)
> printf("[%u] Connected, %u bytes free\n", id, NutHeapAvailable());
> #else
> printf("[%u] Connected, %lu bytes free\n", id, NutHeapAvailable());
> #endif
>
>
> Is that really required? Isn't size_t (like int) 32 bit by
> default?
Yes, size_t is 32 bit but when I tried to compile the original code
using h8300-elf-gcc (or arm-elf-gcc) I got following warning:
httpserv.c:442: warning: unsigned int format, size_t arg (arg 3)
As an example you may try to compile following program using one of
the mentioned compilers with -Wall option.
#include <stdio.h>
#include <stddef.h>
int main(int argc, char *argv[])
{
size_t i = 10;
printf("size_t = %u\n", sizeof(size_t));
printf("i (%%d) = %d\n", i);
printf("i (%%u) = %u\n", i);
printf("i (%%ld) = %ld\n", i);
printf("i (%%lu) = %lu\n", i);
return 0;
}
BTW. Maybe we should use type casting instead of defines in such places?
Regards,
/J.D.
--
Jan Dubiec, jdx at slackware.pl, mobile: +48 602 101787
Głęboka wiara wymaga płytkiego rozumu i nikłej wiedzy.
More information about the En-Nut-Discussion
mailing list