Topic: problem with assertions


Author: shankar@engr.sgi.com (Shankar Unni)
Date: 1995/08/22
Raw View
J. Kanze (kanze@gabi-soft.fr) wrote:

> |>    BOOL
> |>       bSuccess = bTrySomething();

> Get a compiler that understands C++.  The ``declared but not used''
> warning is not applicable to objects;

Ah, but "bSuccess" is not an object: it's a bool. The declaration and
assignment to bSuccess is indeed superfluous if bSuccess is never used
again, as it has no effects unless bSuccess were a volatile..

If we're now saying that a compiler should *never* warn a user about
something which is declared but not used (or in this case, "set but not
used"), because in some cases the user *may* be doing something
"reasonable", then that's a different kettle of fish..
--
Shankar Unni    E-Mail: shankar@sgi.com
Silicon Graphics Inc.   Phone: +1-415-390-2072
URL: http://reality.sgi.com/employees/shankar
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]





Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1995/08/15
Raw View
STIOO (stioo@ift.ulaval.ca) wrote:
|>    ...
|>
|>    BOOL
|>       bSuccess = bTrySomething();

|>    assert(bSuccess);   // I kwnow it must be a success.

|>    ...


|>    When I remove the assert statement  (undefining a keyword) I get
|> a compiler warning: "bSuccess declared but not used".

|>    Is there another writing style that avoids such a message?

Get a compiler that understands C++.  The ``declared but not used''
warning is not applicable to objects; the compiler should know enough to
not generate it if the object has a constructor or a destructor.

While waiting: pipe the compiler output through grep -v 'declared but
not used'.
--
James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils en informatique industrielle--
--Beratung in industrieller Datenverarbeitung
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]





Author: nmein@bifrost.otago.ac.nz (Nick Mein)
Date: 1995/08/07
Raw View
[Followups directed to comp.lang.c++]

STIOO (stioo@ift.ulaval.ca) wrote:

:    BOOL bSuccess = bTrySomething();
:    assert(bSuccess);   // I kwnow it must be a success.

:    When I remove the assert statement  (undefining a keyword) I get
:    a compiler warning: "bSuccess declared but not used".

:    Is there another writing style that avoids such a message?

Microsoft's MFC defines a VERIFY macro which works as an assert, but
when _debug is undefined the expression is still evaluated for its side
effects. Ie, you would use:

     verify(bTrySomething());

--
Nick Mein
MSc Student
Dept of Computer Science
University of Otago
Dunedin
New Zealand.





Author: stioo@ift.ulaval.ca (STIOO)
Date: 1995/08/04
Raw View
   ...

   BOOL
      bSuccess = bTrySomething();

   assert(bSuccess);   // I kwnow it must be a success.

   ...


   When I remove the assert statement  (undefining a keyword) I get
a compiler warning: "bSuccess declared but not used".

   Is there another writing style that avoids such a message?

   Louis Lecomte
   stioo project.