Topic: assert() what?


Author: wehope@ews7.dseg.ti.com (Bill Hope)
Date: Tue, 24 Aug 1993 16:06:11 GMT
Raw View
I am in the process of teaching myself C++ and look at about anything I can get my
hands on..

I was loading the Stack template class from the article that Pete Becker wrote in
DDJ Aug. 93 (Source Included below) and found assert().

I tried to look up assert() in the ARM (1991) and found nothing.

So I tried loading the following two lines into ObjectCenter:

#include "Stack.h"
Stack<int> S1;

And I get the following error message:

Line: 10   E#747   (in FILE: ./Stack.h)   undefined function assert called.

And Pete's email address is not listed in the article (that I could find).

THE QUESTIONS:
1. Is assert() a new addition to C++ or just left out of the article?
2. Is there a place to get updates to my copy of the ARM on the net somewhere?

Thanks for any help.


// Included Source for Stack.h //

template <class Type> class Stack
{
public:
   Stack (): Current (Data) {}

   int ItemsInStack () const { return Current - Data; }

   Type Top () const
      {
      assert (ItemsInStack () != 0);
      return *Current;
      }

   void Push (Type t)
      {
      assert (ItemsInStack () < Size);
      *Current++ = t;
      }

   Type Pop ()
      {
      assert (ItemsInStack () != 0);
      return *(--Current);
      }

private:
   enum { Size = 20 };
   Type Data [Size];
   Type *Current;
};


---
|| Bill Hope       || All Opinions are personal and have not ||
|| ESA - Software Automation     ||    been approved by Upper Management.  ||
|| Texas Instruments, Inc.     ||                                       ||
|| email: wehope@ews7.dseg.ti.com || Any Facts are Facts as I know them;    ||
|| voice: 214.995.5618            ||    Others may have more accurate Facts.||






Author: pete@borland.com (Pete Becker)
Date: Tue, 24 Aug 1993 18:00:20 GMT
Raw View
In article <1993Aug24.160611.5149@mksol.dseg.ti.com>,
Bill Hope <wehope@ews7.dseg.ti.com> wrote:
>I am in the process of teaching myself C++ and look at about anything I can get my
>hands on..
>
>I was loading the Stack template class from the article that Pete Becker wrote in
>DDJ Aug. 93 (Source Included below) and found assert().
>

 assert() is standard C. You need to #include <assert.h> to get it.
 -- Pete




Author: davisonj@bnr.ca (John M Davison)
Date: 24 Aug 1993 18:22:10 GMT
Raw View
        In article <1993Aug24.160611.5149@mksol.dseg.ti.com>
wehope@ews7.dseg.ti.com writes:
>I tried to look up assert() in the ARM (1991) and found nothing.
...
>1. Is assert() a new addition to C++ or just left out of the article?

        The "assert" macro comes from C.  See ANSI X3.159-1989, Section
4.2.1.1, for more information.

>2. Is there a place to get updates to my copy of the ARM on the net somewhere?

        No.  The best you can do is to read comp.std.c++, read trade journals
(e.g. _C++_Report_), and find someone who is on either the SC22 committee or
the JTC1 committee and browse through the documents they receive.  None of
the committee paperwork is availble electronically as far as I know.

--
+--------+ main() { const char c = 'c'; char *pc; const char **pcc = &pc;
|John    |          *pcc = &c; *pc = 'C'; }                         // Whoops!
|Davison | Disclaimer: The information contained in this article is not
+--------+             representative of Northern Telecom and/or BNR.