Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Mar 2008 07:40:02 GMT
From:      linimon@lonesome.com (Mark Linimon)
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/71613: [PATCH] traceroute(8): cleanup of the usr.sbin/traceroute6 code
Message-ID:  <200803160740.m2G7e2En024948@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/71613; it has been noted by GNATS.

From: linimon@lonesome.com (Mark Linimon)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/71613: [PATCH] traceroute(8): cleanup of the usr.sbin/traceroute6 code
Date: Sun, 16 Mar 2008 02:32:55 -0500

 ----- Forwarded message from Dan Lukes <dan@obluda.cz> -----
 
 From: Dan Lukes <dan@obluda.cz>
 To: Bruce Evans <brde@optusnet.com.au>
 Cc: freebsd-bugs@FreeBSD.org, imp@FreeBSD.org
 
 	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
 
 ----- end forwarded message -----



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200803160740.m2G7e2En024948>