From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <andy@warmcat.com>
Received: from mail.warmcat.com (mail.warmcat.com [163.172.24.82])
 by dpdk.org (Postfix) with ESMTP id D04781BE2F
 for <dev@dpdk.org>; Mon, 14 May 2018 02:05:53 +0200 (CEST)
To: Thomas Monjalon <thomas@monjalon.net>
Cc: dev@dpdk.org
References: <152609021699.121661.5295227351721865436.stgit@localhost.localdomain>
 <152609041278.121661.12065395526931802948.stgit@localhost.localdomain>
 <1894250.mJgVCb3rkv@xps>
From: Andy Green <andy@warmcat.com>
Message-ID: <48c0df75-d755-6ba5-675c-1ace856a809d@warmcat.com>
Date: Mon, 14 May 2018 08:05:49 +0800
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
 Thunderbird/52.7.0
In-Reply-To: <1894250.mJgVCb3rkv@xps>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Subject: Re: [dpdk-dev] [PATCH v3 18/24] rte_ether.h: explicit cast avoiding
 truncation warning
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Mon, 14 May 2018 00:05:53 -0000



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