--- Comment #17 from Stewart Gordon <s...@iname.com> 2012-07-26 06:14:15 PDT ---
(In reply to comment #16)
> > How would the programmer suppress this warning because it's deliberate?
> When I wrote that, I was thinking that the developer can initialize in the
> constructor if he really wants it to be non-static. But now I remember that
> structs can't have a default constructor.
Indeed. Moreover, being able to set the value just once in the code, in the
member declaration, could be used to address the ongoing problem with structs
and const-safety by deciding that a struct with a const/immutable member can be
reassigned as long as said member's value is a compile-time constant (in the
absence of other constraints preventing it).
> Personally I think coders should be able to suppress warnings inside a pragma.
> But I think I heard Walter doesn't like that.
The tradition in C++ has been that typical compiler warnings can be suppressed
by making changes at the code level, for example:
- code has no effect - comment it out or cast it to void
- unreachable code - comment it out
- unused parameter - don't name it
- implicit narrowing conversions - use an explicit cast
- counter-intuitive operator precedence - use brackets
It might be that Walter wants to follow this tradition. Or down to problems
with the design of D pragmas.
> Nevertheless it could easily be a
> mistake to use "const int Foo = 7;" instead of "enum" or "static const int",
> and the developer usually won't find out about the mistake without a warning.
It could just as easily, if not more, be an attempt to use that declaration
thinking it'll actually put that member in the structure's memory layout. An
example would be to take a Windows API struct and modify the definition to
hard-code that first member that is just the struct's size.
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------