[cfe-dev] warning with conditional operator and printf, is this a bug ?

Axel Gonzalez loox at e-shell.net
Thu Nov 3 17:46:26 PDT 2011


This is a test case, not sure if its a bug with printf.

This seems strange because both operands are the same type (the one that is 
expected).

Thanks in advance.


please CC me, I'm not suscribed to the list.


--

clang -Wall -o ntohs2 ntohs2.c 
ntohs2.c:10:12: warning: conversion specifies type 'unsigned short' but the 
argument has type
      'int' [-Wformat]
        printf("%hu\n", x < 0 ? x : y);
                ~~^     ~~~~~~~~~~~~~
                %d                                                                              
1 warning generated.

--

#include <stdio.h>
#include <netinet/in.h>

int main()
{
	uint16_t x = htons(80);
	uint16_t y = ntohs(80);
	x = x < 0 ? x : y;
	printf("%hu\n", y);
	printf("%hu\n", x < 0 ? x : y);
	return (0);
}



-- 
Thu Nov  3 18:31:03 2011 GMT

        **
        *****
       ********
       *********
       *********
       ********
        *****
        **      8.




More information about the cfe-dev mailing list