Re: Strange warning with clang and 9RC1 (ntohs)

From: Axel Gonzalez <loox_at_e-shell.net>
Date: Tue, 01 Nov 2011 01:10:36 -0600
Here is the output (short version):

...
(snip)

static __inline __uint16_t
__bswap16_var(__uint16_t _x)
{

 return ((__uint16_t)((_x) << 8 | (_x) >> 8));
}

...
(snip)


int main()
{
 uint16_t x = (__builtin_constant_p(80) ? (__uint16_t)(((__uint16_t)(80)) << 8 
| ((__uint16_t)(80)) >> 8) : __bswap16_var(80));
 printf("%hu\n", (uint16_t)(__builtin_constant_p(x) ? (__uint16_t)
(((__uint16_t)(x)) << 8 | ((__uint16_t)(x)) >> 8) : __bswap16_var(x)));
 printf("%hu\n", (__builtin_constant_p(x) ? (__uint16_t)(((__uint16_t)(x)) << 
8 | ((__uint16_t)(x)) >> 8) : __bswap16_var(x)));
 return (0);
}


% clang -E ntohs.c > ntohs_.c
% clang -Wall -o ntohs ntohs_.c 
In file included from ntohs.c:1:
ntohs.c:8:12: warning: conversion specifies type 'unsigned short' but the 
argument has type
      'int' [-Wformat]
  ...%hu\n", (__builtin_constant_p(x) ? (__uint16_t)(((__uint16_t)(x)) << 8 | 
((__uint16_t)(x)) >> 8) : __bswap16_var(x))...
     ~~^     
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                       
     %d                                                                                                                                                                                         
1 warning generated. 



And I missed it the first mail:

FreeBSD moonlight 9.0-RC1 FreeBSD 9.0-RC1 #0: Fri Oct 28 22:53:45 CDT 2011     
toor_at_moonlight:/usr/obj/usr/src/sys/LXCORE9  i386


Thanks!

A


On Tuesday 01 November 2011 07:56:51 Roman Divacky wrote:
> It doesnt warn here. Can you check with "clang -E" what the ntohs()
> is being expanded to and what the real prototype is?
> 
-- 
Tue Nov  1 01:01:15 2011 GMT

        **
        *****
         ******
         *******
         *******
         ******
        *****
        **      6.
Received on Tue Nov 01 2011 - 06:10:54 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:19 UTC