From owner-freebsd-bugs@FreeBSD.ORG Sat Mar 15 12:59:14 2008 Return-Path: Delivered-To: freebsd-bugs@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3F770106566C; Sat, 15 Mar 2008 12:59:14 +0000 (UTC) (envelope-from dan@obluda.cz) Received: from smtp1.kolej.mff.cuni.cz (smtp1.kolej.mff.cuni.cz [78.128.192.10]) by mx1.freebsd.org (Postfix) with ESMTP id C2FC78FC19; Sat, 15 Mar 2008 12:59:13 +0000 (UTC) (envelope-from dan@obluda.cz) X-Envelope-From: dan@obluda.cz Received: from kgw.obluda.cz (openvpn.ms.mff.cuni.cz [195.113.20.87]) by smtp1.kolej.mff.cuni.cz (8.14.2/8.14.2) with ESMTP id m2FCwvOE035852; Sat, 15 Mar 2008 13:58:58 +0100 (CET) (envelope-from dan@obluda.cz) Message-ID: <47DBC810.3030903@obluda.cz> Date: Sat, 15 Mar 2008 13:58:56 +0100 From: Dan Lukes User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.8.1.12) Gecko/20080302 SeaMonkey/1.1.8 MIME-Version: 1.0 To: Bruce Evans References: <200803150200.m2F206rl078586@freefall.freebsd.org> <20080315151246.L35251@besplex.bde.org> <47DB7DA8.7050400@obluda.cz> <20080315192732.A38703@delplex.bde.org> In-Reply-To: <20080315192732.A38703@delplex.bde.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-bugs@FreeBSD.org, imp@FreeBSD.org Subject: Re: bin/71613: [PATCH] traceroute(8): cleanup of the usr.sbin/traceroute6 code X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Mar 2008 12:59:14 -0000 OK There seems to be several ways to correct the problem. We can avoid the warning by adding "const" or "volatile" or __used or by removing "static". The "remove static" way can't be used - non-static symbol is global variable - so const char copyright[] from one source will collide with the same name variable from another source. It's not problem only when there are one source file only or we can guarantee unique variable name. It seems we need 'static'. Unfortunately, static unused variable can be optimized out. Adding 'const' and/or __used clear the warning, but doesn't prevent "optimized-out" problem. The 'const' shall be used because the string is constant. We can use __used, but it has limited portability. We still have the problem the variable may be optimized out. The 'volatile' is way to tell an ANSI C compiler "this variable may be modified via mechanism you don't know about it" - it mean "count it as used" and "don't optimize it". Note, the 'const' and 'static' are ANSI C keywords also, so compiler knowing 'static' shall handle 'volatile' as well. Conclusion (for the case we can't guarantee the unique name of variable): static MUST const SHALL __used SHALL volatile MUST So my recomentation is: 0: static volatile const char __used copyright[]=... because of __unused the sys/cdefs.h must be included first. The other way to fix it is 1: the sys/copyright.h way - e.g. plain char variable - but the variable must be unique across the sources which sound not so easy for me 2. the __COPYRIGHT way, but 2a: IDSTRING must be corrected first 2b: the '\n' must be removed from the source. sys/cdefs.h must be included first. In my opinion the preference shall be 2a then 0 then 1 or 2b but it's not strict. The commiter shall select the best way. Dan