[En-Nut-Discussion] Compiling with GCC4
Vesa Jääskeläinen
chaac at nic.fi
Tue Mar 7 20:36:57 CET 2006
Harald Kipp wrote:
> Hi,
>
> IMHO this is the most minimal patch to get Nut/OS compiling with GCC 4.0.
> So far tested for ARM only, but AVR should work too.
>
> In order to avoid breaking BTNut, I'll wait for their OK before
> applying it to CVS HEAD.
>
> Harald
Hi Harald,
It could be the most minimal patch, but I would still propose more
clearer source tree approach. It would require more changes to tree now,
but if the functionality is not broken, then it would result in clearer
source tree in longer run. In my opinion data conversion casts should be
avoided if it is possible or it doesn't make the intention clearer.
I think that if there is a string, it should be type of char, and not
unsigned char.
I must admit that I do not have GCC 4 installed now so I cannot test it out.
> diff -ruN nut/include/arch/arm.h nut-gcc4/include/arch/arm.h
> --- nut/include/arch/arm.h 2006-03-02 21:02:05.000000000 +0100
> +++ nut-gcc4/include/arch/arm.h 2006-03-07 18:56:28.000000000 +0100
> @@ -107,13 +107,13 @@
>
> #define main NutAppMain
>
> -#define strlen_P(x) strlen(x)
> -#define strcpy_P(x,y) strcpy(x,y)
> +#define strlen_P(x) strlen((char *)(x))
> +#define strcpy_P(x,y) strcpy(x,(char *)(y))
>
> -#define strcmp_P(x, y) strcmp(x, y)
> +#define strcmp_P(x, y) strcmp((char *)(x), (char *)(y))
> #define memcpy_P(x, y, z) memcpy(x, y, z)
>
> -#define fputs_P(x, y) fputs(x, y)
> +#define fputs_P(x, y) fputs((char *)(x), y)
> #define fprintf_P fprintf
> #define printf_P printf
Why casts here? How big job it would be to change the users and not to
add cast to the macro declarations?
> diff -ruN nut/include/dev/chat.h nut-gcc4/include/dev/chat.h
> --- nut/include/dev/chat.h 2005-04-30 19:42:41.000000000 +0200
> +++ nut-gcc4/include/dev/chat.h 2006-03-07 18:57:40.000000000 +0100
> @@ -98,9 +98,9 @@
> int chat_fd;
> u_char chat_arg;
> u_char chat_aborts;
> - u_char *chat_abort[CHAT_MAX_ABORTS];
> + char *chat_abort[CHAT_MAX_ABORTS];
> u_char chat_abomat[CHAT_MAX_ABORTS];
> - u_char *chat_report_search;
> + char *chat_report_search;
> u_char chat_repmat;
> char chat_report_state;
> } NUTCHAT;
> diff -ruN nut/pro/resolv.c nut-gcc4/pro/resolv.c
> --- nut/pro/resolv.c 2006-01-23 20:52:10.000000000 +0100
> +++ nut-gcc4/pro/resolv.c 2006-03-07 19:18:50.000000000 +0100
> @@ -164,7 +164,7 @@
> static u_short AddName(u_char * cp, CONST u_char * name)
[snip]
Why not change those params to char too ? I think this would eliminate
needed cast in this function. It might also require changes to local
variable types and used structures, but would be clearer.
> diff -ruN nut/pro/wins.c nut-gcc4/pro/wins.c
> --- nut/pro/wins.c 2005-11-24 10:46:55.000000000 +0100
> +++ nut-gcc4/pro/wins.c 2006-03-07 19:20:26.000000000 +0100
> @@ -89,7 +89,7 @@
>
> /* ********************************************************* */
> /* name : netbios label (15 chars max), ipaddr : network ordered IP
> address bytes */
> -int NutWinsNameQuery(u_char * name, u_long ipaddr)
> +int NutWinsNameQuery(char * name, u_long ipaddr)
> {
> WINSHEADER *pkt = NULL;
> u_char *encoded = NULL;
> @@ -129,7 +129,7 @@
> (pkt->namelen != 0x20) || /* */
> (ntohs(pkt->type) != 32) || /* */
> (ntohs(pkt->class) != 1) || /* */
> - (strcmp(pkt->name, encoded)))
> + (strcmp((char *)pkt->name, (char *)encoded)))
> continue; /* bad request, try again */
> /* printf("Name=%s recognized\r\n", name); */
> /* build RFC1002 Positive Name Query Response */
Why not change pkt->name's type to char too ? And depending on what
encoded stores, it could also be changed to char.
Thanks,
Vesa Jääskeläinen
More information about the En-Nut-Discussion
mailing list