From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Green Subject: Re: [PATCH v3 18/24] rte_ether.h: explicit cast avoiding truncation warning Date: Mon, 14 May 2018 08:05:49 +0800 Message-ID: <48c0df75-d755-6ba5-675c-1ace856a809d@warmcat.com> References: <152609021699.121661.5295227351721865436.stgit@localhost.localdomain> <152609041278.121661.12065395526931802948.stgit@localhost.localdomain> <1894250.mJgVCb3rkv@xps> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Cc: dev@dpdk.org To: Thomas Monjalon Return-path: Received: from mail.warmcat.com (mail.warmcat.com [163.172.24.82]) by dpdk.org (Postfix) with ESMTP id D04781BE2F for ; Mon, 14 May 2018 02:05:53 +0200 (CEST) In-Reply-To: <1894250.mJgVCb3rkv@xps> Content-Language: en-US List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 05/14/2018 01:02 AM, Thomas Monjalon wrote: > 12/05/2018 04:00, Andy Green: >> /projects/lagopus/src/dpdk/build/include/rte_ether.h:213:13: >> warning: conversion from 'int' to 'uint8_t' >> {aka 'unsigned char'} may change value [-Wconversion] >> addr[0] &= ~ETHER_GROUP_ADDR; >> /* clear multicast bit */ > [..] >> rte_memcpy(addr, p, ETHER_ADDR_LEN); >> - addr[0] &= ~ETHER_GROUP_ADDR; /* clear multicast bit */ >> + addr[0] &= (uint8_t)~ETHER_GROUP_ADDR; /* clear multicast bit */ >> addr[0] |= ETHER_LOCAL_ADMIN_ADDR; /* set local assignment bit */ > > ETHER_GROUP_ADDR and ETHER_LOCAL_ADMIN_ADDR are defined macros, > they have no type, so I don't understand the need for casting. > And I don't understand why it is not needed for ETHER_LOCAL_ADMIN_ADDR. Both of those manifest constants are 0x1. But ~ETHER_GROUP_ADDR is a "big number" in an int. The compiler notices a definite truncation if you try to put 0xfffffffe in a uint8_t and complains. If you try to put 0x01 in a uint8_t, the compiler feels it was OK. -Andy