shlwapi: Cast-qual warnings fix (2 of 4)

Andrew Talbot Andrew.Talbot at talbotville.com
Thu Nov 16 14:57:52 CST 2006


Dimi Paun wrote:

> 
> On Thu, November 16, 2006 12:42 pm, Andrew Talbot wrote:
>> As I understand it, declaring them static means that the storage will be
>> assigned and initialised at compile time, rather than run time, since the
>> size and contents are already known.
> 
> Correct. However, if they aren't constant, it means that they may
> get modified, which is an obvious problem. Making them non-static
> would indeed initialize them at runtime (small cost), but they would
> be guaranteed to have the value that we expect always.
> 
> I haven't looked at the code, maybe you can prove they are indeed
> constant, but that's ugly. I'd take the trivial runtime hit, for
> the sake of cleanliness.
> 

I did run this by Alexandre at one point, because this concern was expressed
to me by one or two other prominent members of the Wine community, and he
said "They should be static always, there's no reason to make the compiler
create a separate copy at run-time, which will happen with automatic
variables." The hit is not so much in the initialisation as in the creation
of the storage, which has to take place for each invocation.

Making the variables automatic guarantees that they will be correct at the
start of each invocation of the function they are in, but doesn't guarantee
that another function with non-const formal parameters that it, in turn,
calls won't mess them up during that invocation, and the reason why we are
deconstifying logically-constant variables is that we are passing them to
non-const-correct C standard library or SDK functions. So once you take
away the const qualifier from a variable it will be vulnerable to potential
corruption by a bad sub-function, whether that variable is automatic or
static.

I make these assertions in humble recognition of the fact that I could be
speaking from a position of profound ignorance. In the end, my confidence
rests in the firm belief that Alexandre would reject this form of fix if he
considered it unacceptable.

-- Andy.





More information about the wine-devel mailing list