Subject: Re: misc/6185: Warning when using ntohs() and friends
To: None <netbsd-bugs@netbsd.org>
From: Dave Sainty <dave@dtsp.co.nz>
List: netbsd-bugs
Date: 09/26/1998 18:39:50
Peter Simons writes:
> >Number: 6185
> >Category: misc
> >Synopsis: Warning when using ntohs() and friends
> >Confidential: no
> >Severity: non-critical
> >Priority: medium
> >Responsible: misc-bug-people (Misc Bug People)
> >State: open
> >Class: change-request
> >Submitter-Id: net
> >Arrival-Date: Mon Sep 21 04:20:00 1998
> >Last-Modified:
> >Originator: Peter Simons
> >Organization:
>
> int i = ntohs(htons(0));
>
> with egcs 1.1 will give the following warnings:
>
> | simons@peti:/tmp$ gcc -ansi -pedantic test.c -o test
> | test.cpp: In function `int main()':
This patch fixes this problem. There was also a send-pr for this as
kern/3562, but its proposed fix reduces the produced code efficiency.
This fix is less pedantic though :) (That is, it can miss
pedantic-warning generating code passed as a parameter to htons() and
not generate a warning. I doubt anyone cares. :)
According to kern/3562 it's a problem for pc532. I don't have that
file here, but the fix will be pretty similar.
--- sys/arch/i386/include/endian.h.orig Sat Aug 15 23:12:00 1998
+++ sys/arch/i386/include/endian.h Sat Sep 26 18:23:04 1998
@@ -116,14 +116,14 @@
#if defined(_KERNEL) && !defined(_LKM) && !defined(I386_CPU)
#define __byte_swap_long_variable(x) \
-({ register in_addr_t __x = (x); \
+__extension__ ({ register in_addr_t __x = (x); \
__asm ("bswap %1" \
: "=r" (__x) \
: "0" (__x)); \
__x; })
#else
#define __byte_swap_long_variable(x) \
-({ register in_addr_t __x = (x); \
+__extension__ ({ register in_addr_t __x = (x); \
__asm ("rorw $8, %w1\n\trorl $16, %1\n\trorw $8, %w1" \
: "=r" (__x) \
: "0" (__x)); \
@@ -131,7 +131,7 @@
#endif /* _KERNEL && ... */
#define __byte_swap_word_variable(x) \
-({ register in_port_t __x = (x); \
+__extension__ ({ register in_port_t __x = (x); \
__asm ("rorw $8, %w1" \
: "=r" (__x) \
: "0" (__x)); \