This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/12194] New: htons() gives warning if compiled with gcc -Wconversion


http://sourceware.org/bugzilla/show_bug.cgi?id=12194

           Summary: htons() gives warning if compiled with gcc
                    -Wconversion
           Product: glibc
           Version: 2.10
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: johan162@gmail.com


The following (legitimate) code will generate a warning when both -O2 and 
-Wconversion is enabled but not when only -Wconversion is enabled. 

Code:
#include <arpa/inet.h>
// Nonsense code to illustrate problem
int main(void) {
    uint16_t portnbr=0;
    uint16_t n_portnbr = htons(portnbr);
    exit(0);
}

With optimization


$> gcc -std=gnu99 -Wconversion -Werror -O2 -c tsthtons.c
cc1: warnings being treated as errors
tsthtons.c: In function âmainâ:
tsthtons.c:6: error: conversion to âshort unsigned intâ from âintâ may alter
its value


and without


$>gcc -std=gnu99 -Wconversion -Werror  -c tsthtons.c
$>

in both cases

gcc --version
gcc (SUSE Linux) 4.4.1 [gcc-4_4-branch revision 150839]
Copyright (C) 2009 Free Software Foundation, Inc.


and gnu clib v2.10.1

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]