Re: unused for all platforms



Hi,

On Mon, 2002-02-18 at 16:13, Sander Vesik wrote:
> On Mon, 18 Feb 2002, Miroslaw Dobrzanski-Neumann wrote:
> 
> > On Mon, Feb 18, 2002 at 03:10:14PM +0100, Daniel Egger wrote:
> > > Am Mon, 2002-02-18 um 09.49 schrieb Miroslaw Dobrzanski-Neumann:
> > > 
> > > > As I know there is no compiler that generates code for statements like
> > > > "p = *&p"
> > > 
> > > Actually that would have to be "p = p" which is valid C and means
> > > what it reads (i.e. Initialise p with the value it had before, whatever
> > > that was; probably random).There was some hefty discussion on the gcc
> > > mailinglist whether that really is the proper fix to prevent the
> > > "variable blah might be used uninitialised" warnings and the only
> > > conclusion they have reached was that it's totally valid C but should
> > > be discouraged.
> > why?
> > p = *&p guarantees that p does not go into cpu register (its address is
> > taken).
> 
> No, it only gurantees that its not a "pure" register only variable. p=*&p
> also probably refreshes the state of the in-register copy of the variable
> from thew in-memory copy (in case someone went and overwrote it behind
> everybodies back).
> 
> What kind of optimisations it inhibits (after all, compilers with good
> optimisations do a bit more flow analysis and don't make far
> reaching assumptions just because an address of a variable was taken
> somewhere) to make a compiler look at the computer as having m2m
> operations is compiler (version) dependant.

This is already filed in bug #52026.

The best solution is to simply write "(void)var" to avoid warning for
unused var and "(void)&var"  to avoid warning for uninitialized var.
This work for gcc and does not generate any code.

And things like 

#define G_UNUSED_VARIABLE(v) #error "not used variable"

of course wont work, as the preprocessor is not run twice on the input
file and even in release files you would want to have unused vars, e.g.
for callback functions, where you want to ignore a parameter.

Bye,
Sebastian
-- 
Sebastian Wilhelmi
mailto:wilhelmi ira uka de
http://goethe.ira.uka.de/~wilhelmi





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]