Docs: Section on local variables

Stewart Gordon smjg_1998 at yahoo.com
Wed Apr 25 14:47:50 PDT 2012


On 25/04/2012 21:12, Andrej Mitrovic wrote:
<snip>
> I'm really only talking about:
> void a() {
> int x;
> }

What is the distinction you're making exactly?

> And of course:
> void a() {
> bool state;
> ...
> if (state) { }
> }

You mean an empty if body should trigger something?  Or shouldn't?

OK, so I can see a similarity in that it's likely to occur when disabling portions of code 
for debugging purposes.  Not just debugging the program in which it is present, but also 
creating testcases for compiler/library bug reports.

> I'd like the warnings to be individually selectable, just like in GCC.
>
> Btw, here's a trick question, should the compiler warn about this case?
>
> void main() {
>      new Foo();  // or even Foo foo = new Foo;
> }

An interesting one.  Sometimes a constructor may hook the object up to something.  I've 
probably done this myself on a number of occasions.  Though I can't think of examples 
OTTOMH.  But an example in C++ comes from my last job.  The application framework 
developed in-house includes a class template used to trigger events on construction and 
destruction.  To use it, one would just construct an object of that type.  In many cases, 
it would just be a declaration of a variable of that type (since C++ classes are value 
types) - the variable will never be used again, but the object's construction triggers stuff.

Stewart.


More information about the Digitalmars-d-learn mailing list