home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / g / bug / 2330 < prev    next >
Encoding:
Text File  |  1993-01-25  |  23.0 KB  |  781 lines

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!ee.edinburgh.ac.UK!htf
  2. From: htf@ee.edinburgh.ac.UK
  3. Newsgroups: gnu.g++.bug
  4. Subject: problem with new[]
  5. Date: 25 Jan 1993 21:05:14 -0500
  6. Organization: GNUs Not Usenet
  7. Lines: 768
  8. Sender: daemon@cis.ohio-state.edu
  9. Approved: bug-g++@prep.ai.mit.edu
  10. Distribution: gnu
  11. Message-ID: <11270.9301251430@almer.ee.ed.ac.uk>
  12.  
  13. Hi Gnu,
  14.  
  15. There appears to be a deviation from expected c++ behavior with the
  16. new[] operator call. According to the Lippman C++ Primer calls to
  17. allocate an array of objects using "new some_class [n]" should go
  18. through the default allocator, and bypass any overloaded class member
  19. operator functions. The following code demonstrates that this does not
  20. occur with g++-2.3.3.
  21.  
  22. ------example code-----
  23. # 1 "foo.cc"
  24. # 1 "/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/g++-include/stdlib.h" 1
  25.  
  26. # 1 "/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/g++-include/stddef.h" 1
  27.  
  28. extern "C" {
  29.  
  30. # 1 "/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/include/stddef.h" 1 3
  31.  
  32. # 43 "/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/include/stddef.h" 3
  33.  
  34. typedef int ptrdiff_t;
  35.  
  36. typedef int size_t;
  37.  
  38. typedef __wchar_t wchar_t;
  39.  
  40. # 179 "/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/include/stddef.h" 3
  41.  
  42. # 7 "/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/g++-include/stddef.h" 2
  43.  
  44. }
  45.  
  46. # 6 "/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/g++-include/stdlib.h" 2
  47.  
  48. extern "C" {
  49.  
  50. int       abs(int);
  51.  
  52. void volatile abort(void);
  53.  
  54. double    atof(const char*);
  55. int       atoi(const char*);
  56. long      atol(const char*);
  57.  
  58. int       atexit(auto void (*p) (void));
  59. int       bsearch (const void *, const void *, size_t, 
  60.                    size_t, auto int (*ptf)(const void*, const void*));
  61. void*     calloc(size_t, size_t);
  62. void      cfree(void*);
  63.  
  64. void volatile exit(int);
  65.  
  66. char*     fcvt(double, int, int*, int*);
  67. void      free(void*);
  68. char*     getenv(const char*);
  69. int       getopt(int, char * const *, const char*);
  70. int       getpw(int, char*);
  71. char*     gcvt(double, int, char*);
  72. char*     ecvt(double, int, int*, int*);
  73. extern char**   environ;
  74.  
  75. long      labs(long);
  76. void*     malloc(size_t);
  77. size_t    malloc_usable_size(void*);
  78. int       putenv(const char*);
  79. extern char*    optarg;
  80. extern int      opterr;
  81. extern int      optind;
  82. void      qsort(void*, size_t, size_t, auto int (*ptf)(void*,void*));
  83. int       rand(void);
  84. void*     realloc(void*, size_t);
  85. int       setkey(const char*);
  86. int       srand(unsigned int);
  87. double    strtod(const char*, char**);
  88. long      strtol(const char*, char**, int);
  89. unsigned long stroul(const char**, int);
  90. int       system(const char*);
  91.  
  92. long      random(void);
  93. void      srandom(int);
  94. char*     setstate(char*);
  95. char*     initstate(unsigned, char*, int);
  96.  
  97. double    drand48(void);
  98. void      lcong48(short*);
  99. long      jrand48(short*);
  100. long      lrand48(void);
  101. long      mrand48(void);
  102. long      nrand48(short*);
  103. short*    seed48(short*);
  104. void      srand48(long);
  105.  
  106. char*     ctermid(char*);
  107. char*     cuserid(char*);
  108. char*     tempnam(const char*, const char*);
  109. char*     tmpnam(char*);
  110.  
  111. }
  112.  
  113. # 1 "foo.cc" 2
  114.  
  115. # 1 "/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/g++-include/stream.h" 1
  116.  
  117. # 1 "/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/g++-include/iostream.h" 1
  118.  
  119. #pragma interface
  120.  
  121. # 1 "/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/g++-include/streambuf.h" 1
  122.  
  123. #pragma interface
  124.  
  125. # 1 "/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/g++-include/_G_config.h" 1
  126.   
  127. typedef long _G_clock_t;
  128. typedef short _G_dev_t;
  129. typedef long   _G_fpos_t;
  130. typedef unsigned short _G_gid_t;
  131. typedef unsigned long _G_ino_t;
  132. typedef unsigned short _G_mode_t;
  133. typedef short _G_nlink_t;
  134. typedef long _G_off_t;
  135. typedef int _G_pid_t;
  136. typedef int _G_ptrdiff_t;
  137. typedef int _G_sigset_t;
  138. typedef int _G_size_t;
  139. typedef long _G_time_t;
  140. typedef unsigned short _G_uid_t;
  141. typedef unsigned short _G_wchar_t;
  142. typedef int   _G_ssize_t;
  143. typedef char * _G_va_list;
  144.  
  145. # 25 "/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/g++-include/streambuf.h" 2
  146.  
  147. class ostream; class streambuf; class backupbuf;
  148.  
  149. extern "C" int __underflow(streambuf*);
  150. extern "C" int __overflow(streambuf*, int);
  151.  
  152. typedef _G_off_t streamoff;
  153. typedef _G_off_t streampos;  
  154.  
  155. typedef unsigned long __fmtflags;
  156. typedef unsigned char __iostate;
  157.  
  158. struct _ios_fields {  
  159.     streambuf *_strbuf;
  160.     ostream* _tie;
  161.     int _width;
  162.     __fmtflags _flags;
  163.     _G_wchar_t _fill;
  164.     __iostate _state;
  165.     __iostate _exceptions;
  166.     int _precision;
  167. };
  168.  
  169. enum state_value {
  170.     _good = 0 ,
  171.     _eof = 1 ,
  172.     _fail = 2 ,
  173.     _bad = 4  };
  174. enum open_mode {
  175.     input = 1 ,
  176.     output = 2 ,
  177.     atend = 4 ,
  178.     append = 8  };
  179.  
  180. class ios : public _ios_fields {
  181.   public:
  182.     typedef __fmtflags fmtflags;
  183.     typedef int iostate;
  184.     typedef int openmode;
  185.     enum io_state {
  186.     goodbit = 0 ,
  187.     eofbit = 1 ,
  188.     failbit = 2 ,
  189.     badbit = 4  };
  190.     enum open_mode {
  191.     in = 1 ,
  192.     out = 2 ,
  193.     ate = 4 ,
  194.     app = 8 ,
  195.     trunc = 16 ,
  196.     nocreate = 32 ,
  197.     noreplace = 64 ,
  198.     bin = 128  };
  199.     enum seek_dir { beg, cur, end};
  200.      
  201.     enum { skipws=01, left=02, right=04, internal=010,
  202.        dec=020, oct=040, hex=0100,
  203.        showbase=0200, showpoint=0400, uppercase=01000, showpos=02000,
  204.        scientific=04000, fixed=010000, unitbuf=020000, stdio=040000,
  205.        dont_close=0x80000000  
  206.        };
  207.     enum {  
  208.     basefield=dec+oct+hex,
  209.     floatfield = scientific+fixed,
  210.     adjustfield = left+right+internal
  211.     };
  212.  
  213. # 138 "/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/g++-include/streambuf.h"
  214.  
  215.     ostream* tie() const { return _tie; }
  216.     ostream* tie(ostream* val) { ostream* save=_tie; _tie=val; return save; }
  217.  
  218.     _G_wchar_t fill() const { return (_G_wchar_t)_fill; }
  219.     _G_wchar_t fill(_G_wchar_t newf)
  220.     {_G_wchar_t oldf = (_G_wchar_t)_fill; _fill = (char)newf; return oldf;}
  221.     fmtflags flags() const { return _flags; }
  222.     fmtflags flags(fmtflags new_val) {
  223.     fmtflags old_val = _flags; _flags = new_val; return old_val; }
  224.     int precision() const { return _precision; }
  225.     int precision(int newp) {
  226.     unsigned short oldp = _precision; _precision = (unsigned short)newp;
  227.     return oldp; }
  228.     fmtflags setf(fmtflags val) {
  229.     fmtflags oldbits = _flags;
  230.     _flags |= val; return oldbits; }
  231.     fmtflags setf(fmtflags val, fmtflags mask) {
  232.     fmtflags oldbits = _flags;
  233.     _flags = (_flags & ~mask) | (val & mask); return oldbits; }
  234.     fmtflags unsetf(fmtflags mask) {
  235.     fmtflags oldbits = _flags & mask;
  236.     _flags &= ~mask; return oldbits; }
  237.     int width() const { return _width; }
  238.     int width(int val) { int save = _width; _width = val; return save; }
  239.  
  240.     void _throw_failure() { }
  241.  
  242.     streambuf* rdbuf() const { return _strbuf; }
  243.     void clear(iostate state = 0) {
  244.     _state = _strbuf ? state : state|badbit;
  245.     if (_state & _exceptions) _throw_failure(); }
  246.     void set(iostate flag) { _state |= flag;
  247.     if (_state & _exceptions) _throw_failure(); }
  248.     int good() const { return _state == 0; }
  249.     int eof() const { return _state & ios::eofbit; }
  250.     int fail() const { return _state & (ios::badbit|ios::failbit); }
  251.     int bad() const { return _state & ios::badbit; }
  252.     iostate rdstate() const { return _state; }
  253.     operator void*() const { return fail() ? (void*)0 : (void*)(-1); }
  254.     int operator!() const { return fail(); }
  255.     iostate exception(iostate enable) {
  256.     iostate old = _exceptions; _exceptions = enable;
  257.     if (_state & _exceptions) _throw_failure();
  258.     return old; }
  259.  
  260.     static int sync_with_stdio(int on);
  261.     static void sync_with_stdio() { sync_with_stdio(1); }
  262.  
  263.     void unset(state_value flag) { _state &= ~flag; }
  264.     void close();
  265.     int is_open();
  266.     int readable();
  267.     int writable();
  268.  
  269.   protected:
  270.     ios(streambuf* sb = 0, ostream* tie = 0);
  271.     virtual ~ios();
  272.     void init(streambuf* sb) { _state=0; _strbuf=sb; }
  273. };
  274.  
  275. typedef ios::seek_dir _seek_dir;
  276.  
  277. class streammarker {
  278.     friend class streambuf;
  279.  
  280.     friend int __underflow(streambuf*);
  281.  
  282.     struct streammarker *_next;   
  283.     streambuf *_sbuf;  
  284.     streampos _spos;  
  285.     void set_streampos(streampos sp) { _spos = sp; }
  286.     void set_offset(int offset) { _pos = offset; _spos = (streampos)(-2); }
  287.      
  288.     int _pos;
  289.   public:
  290.     streammarker(streambuf *sb);
  291.     ~streammarker();
  292.     int saving() { return  _spos == -2; }
  293.     int delta(streammarker&);
  294.     int delta();
  295. };
  296.  
  297. struct __streambuf {
  298.      
  299.     int _flags;         
  300.     char* _gptr;     
  301.     char* _egptr;     
  302.     char* _eback;     
  303.     char* _pbase;     
  304.     char* _pptr;     
  305.     char* _epptr;     
  306.     char* _base;     
  307.     char* _ebuf;     
  308.     struct streambuf *_chain;
  309.  
  310.     friend class streammarker;
  311.     char *_other_gbase;  
  312.     char *_aux_limit;   
  313.     char *_other_egptr;  
  314.     streammarker *_markers;
  315.  
  316.     unsigned short _cur_column;
  317.     char _unused;
  318.     char _shortbuf[1];
  319. };
  320.  
  321. extern unsigned __adjust_column(unsigned start, const char *line, int count);
  322.  
  323. struct streambuf : private __streambuf {
  324.     friend class ios;
  325.     friend class istream;
  326.     friend class ostream;
  327.     friend class streammarker;
  328.  
  329.     friend int __underflow(streambuf*);
  330.  
  331.   protected:
  332.     static streambuf* _list_all;  
  333.     streambuf*& xchain() { return _chain; }
  334.     void _un_link();
  335.     void _link_in();
  336.     char* gptr() const { return _gptr; }
  337.     char* pptr() const { return _pptr; }
  338.     char* egptr() const { return _egptr; }
  339.     char* epptr() const { return _epptr; }
  340.     char* pbase() const { return _pbase; }
  341.     char* eback() const { return _eback; }
  342.     char* base() const { return _base; }
  343.     char* ebuf() const { return _ebuf; }
  344.     int blen() const { return _ebuf - _base; }
  345.     void xput_char(char c) { *_pptr++ = c; }
  346.     int xflags() { return _flags; }
  347.     int xflags(int f) { int fl = _flags; _flags = f; return fl; }
  348.     void xsetflags(int f) { _flags |= f; }
  349.     void xsetflags(int f, int mask) { _flags = (_flags & ~mask) | (f & mask); }
  350.     void gbump(int n) { _gptr += n; }
  351.     void pbump(int n) { _pptr += n; }
  352.     void setb(char* b, char* eb, int a=0);
  353.     void setp(char* p, char* ep) { _pbase=_pptr=p; _epptr=ep; }
  354.     void setg(char* eb, char* g, char *eg) { _eback=eb; _gptr=g; _egptr=eg; }
  355.     char *shortbuf() { return _shortbuf; }
  356.  
  357.     int in_backup() { return _flags & 0x100 ; }
  358.      
  359.     char *Gbase() { return in_backup() ? _other_gbase : _eback; }
  360.      
  361.     char *eGptr() { return in_backup() ? _other_egptr : _egptr; }
  362.      
  363.     char *Bbase() { return in_backup() ? _eback : _other_gbase; }
  364.     char *Bptr() { return _aux_limit; }
  365.      
  366.     char *eBptr() { return in_backup() ? _egptr : _other_egptr; }
  367.     char *Nbase() { return _other_gbase; }
  368.     char *eNptr() { return _other_egptr; }
  369.     int have_backup() { return _other_gbase != ((void *)0) ; }
  370.     int have_markers() { return _markers != ((void *)0) ; }
  371.     int _least_marker();
  372.     void switch_to_main_get_area();
  373.     void switch_to_backup_area();
  374.     void free_backup_area();
  375.     void unsave_markers();  
  376.     int put_mode() { return _flags & 0x800 ; }
  377.     int switch_to_get_mode();
  378.     
  379.     streambuf(int flags=0);
  380.   public:
  381.     static int flush_all();
  382.     static void flush_all_linebuffered();  
  383.     virtual int underflow() = 0;  
  384.     virtual int overflow(int c = (-1) ) = 0;  
  385.     virtual int doallocate();
  386.     virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
  387.     virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out);
  388.     int seekmark(streammarker& mark, int delta = 0);
  389.     int sputbackc(char c);
  390.     int sungetc();
  391.     virtual ~streambuf();
  392.     int unbuffered() { return _flags & 2  ? 1 : 0; }
  393.     int linebuffered() { return _flags & 0x200  ? 1 : 0; }
  394.     void unbuffered(int i)
  395.     { if (i) _flags |= 2 ; else _flags &= ~2 ; }
  396.     void linebuffered(int i)
  397.     { if (i) _flags |= 0x200 ; else _flags &= ~0x200 ; }
  398.     int allocate() {  
  399.     if (base() || unbuffered()) return 0;
  400.     else return doallocate(); }
  401.      
  402.     void allocbuf() { if (base() == ((void *)0) ) doallocbuf(); }
  403.     void doallocbuf();
  404.     virtual int sync();
  405.     virtual int pbackfail(int c);
  406.     virtual streambuf* setbuf(char* p, int len);
  407.     int in_avail() { return _egptr - _gptr; }
  408.     int out_waiting() { return _pptr - _pbase; }
  409.     virtual int xsputn(const char* s, int n);
  410.     int sputn(const char* s, int n) { return xsputn(s, n); }
  411.     int padn(char pad, int n);  
  412.     virtual int xsgetn(char* s, int n);
  413.     int sgetn(char* s, int n) { return xsgetn(s, n); }
  414.     int ignore(int);
  415.     virtual int get_column();
  416.     virtual int set_column(int);
  417.     long sgetline(char* buf, _G_size_t n, char delim, int putback_delim);
  418.     int sbumpc() {
  419.     if (_gptr >= _egptr && __underflow(this) == (-1) ) return (-1) ;
  420.     else return *(unsigned char*)_gptr++; }
  421.     int sgetc() {
  422.     if (_gptr >= _egptr && __underflow(this) == (-1) ) return (-1) ;
  423.     else return *(unsigned char*)_gptr; }
  424.     int snextc() {
  425.     if (_gptr >= _egptr && __underflow(this) == (-1) ) return (-1) ;
  426.     return _gptr++, sgetc(); }
  427.     int sputc(int c) {
  428.     if (_pptr >= _epptr) return __overflow(this, (unsigned char)c);
  429.     else return *_pptr++ = c, (unsigned char)c; }
  430.     void stossc() { if (_gptr < _egptr) _gptr++; }
  431.     int vscan(char const *fmt0, _G_va_list ap, ios* stream = ((void *)0) );
  432.     int scan(char const *fmt0 ...);
  433.     int vform(char const *fmt0, _G_va_list ap);
  434.     int form(char const *fmt0 ...);
  435.  
  436. };
  437.  
  438. class backupbuf : public streambuf {
  439.     friend class streammarker;
  440.   protected:
  441.     backupbuf(int flags=0) : streambuf(flags|0x4000 ) { }
  442.   public:
  443.     virtual int pbackfail(int c);
  444.     virtual int underflow();
  445.     virtual int overflow(int c = (-1) );
  446. };
  447.  
  448. struct __file_fields {
  449.     short _fileno;
  450.     int _blksize;
  451.     _G_fpos_t  _offset;
  452.  
  453. };
  454.  
  455. class filebuf : public backupbuf {
  456.   protected:
  457.     struct __file_fields _fb;
  458.     void init();
  459.   public:
  460.     static const int openprot;  
  461.     filebuf();
  462.     filebuf(int fd);
  463.     filebuf(int fd, char* p, int len);
  464.     ~filebuf();
  465.     filebuf* attach(int fd);
  466.     filebuf* open(const char *filename, const char *mode);
  467.     filebuf* open(const char *filename, ios::openmode mode, int prot = 0664);
  468.     virtual int underflow();
  469.     virtual int overflow(int c = (-1) );
  470.     int is_open() const { return _fb._fileno >= 0; }
  471.     int fd() const { return is_open() ? _fb._fileno : (-1) ; }
  472.     filebuf* close();
  473.     virtual int doallocate();
  474.     virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
  475.     virtual streambuf* setbuf(char* p, int len);
  476.     int xsputn(const char* s, int n);
  477.     int xsgetn(char* s, int n);
  478.     virtual int sync();
  479.   protected:  
  480.  
  481.     int is_reading() { return eback() != egptr(); }
  482.     char* cur_ptr() { return is_reading() ?  gptr() : pptr(); }
  483.      
  484.     char* file_ptr() { return eGptr(); }
  485.     int do_write(const char *data, int to_do);
  486.     int do_flush() { return do_write(_pbase, _pptr-_pbase); }
  487.      
  488.     virtual _G_ssize_t sys_read(char* buf, _G_size_t size);
  489.     virtual _G_fpos_t  sys_seek(_G_fpos_t , _seek_dir);
  490.     virtual _G_ssize_t sys_write(const void*, long);
  491.     virtual int sys_stat(void*);  
  492.     virtual int sys_close();
  493. };
  494.  
  495. inline ios::ios(streambuf* sb  , ostream* tie  ) {
  496.         _state = sb ? ios::goodbit : ios::badbit; _exceptions=0;
  497.         _strbuf=sb; _tie = tie; _width=0; _fill=' ';
  498.         _flags=ios::skipws|ios::dec; _precision=6; }
  499. inline ios::~ios() {
  500.     if (!(_flags & (unsigned int)ios::dont_close)) delete _strbuf; }
  501.  
  502. # 24 "/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/g++-include/iostream.h" 2
  503.  
  504. class istream; class ostream;
  505. typedef ios& (*__manip)(ios&);
  506. typedef istream& (*__imanip)(istream&);
  507. typedef ostream& (*__omanip)(ostream&);
  508.  
  509. extern istream& ws(istream& ins);
  510. extern ostream& flush(ostream& outs);
  511. extern ostream& endl(ostream& outs);
  512. extern ostream& ends(ostream& outs);
  513.  
  514. class ostream : virtual public ios
  515. {
  516.      
  517.     void do_osfx();
  518.   public:
  519.     ostream() { }
  520.     ostream(streambuf* sb, ostream* tied=((void *)0) );
  521.     int opfx() {
  522.     if (!good()) return 0; else { if (_tie) _tie->flush(); return 1;} }
  523.     void osfx() { if (flags() & (ios::unitbuf|ios::stdio))
  524.               do_osfx(); }
  525.     streambuf* ostreambuf() const { return _strbuf; }
  526.     ostream& flush();
  527.     ostream& put(char c) { _strbuf->sputc(c); return *this; }
  528.     ostream& put(unsigned char c) { return put((char)c); }
  529.  
  530.     ostream& write(const char *s, int n);
  531.     ostream& write(const unsigned char *s, int n) { return write((const char*)s, n);}
  532.  
  533.     ostream& put(signed char c) { return put((char)c); }
  534.     ostream& write(const signed char *s, int n) { return write((const char*)s, n);}
  535.  
  536.     ostream& write(const void *s, int n) { return write((const char*)s, n);}
  537.     ostream& seekp(streampos);
  538.     ostream& seekp(streamoff, _seek_dir);
  539.     streampos tellp();
  540.     ostream& form(const char *format ...);
  541.     ostream& vform(const char *format, _G_va_list args);
  542.  
  543.     ostream& operator<<(char c);
  544.     ostream& operator<<(unsigned char c) { return (*this) << (char)c; }
  545.  
  546.     ostream& operator<<(signed char c) { return (*this) << (char)c; }
  547.  
  548.     ostream& operator<<(const char *s);
  549.     ostream& operator<<(const unsigned char *s)
  550.     { return (*this) << (const char*)s; }
  551.  
  552.     ostream& operator<<(const signed char *s)
  553.     { return (*this) << (const char*)s; }
  554.  
  555.     ostream& operator<<(void *p);
  556.     ostream& operator<<(int n);
  557.     ostream& operator<<(unsigned int n);
  558.     ostream& operator<<(long n);
  559.     ostream& operator<<(unsigned long n);
  560.  
  561.     ostream& operator<<(long long n);
  562.     ostream& operator<<(unsigned long long n);
  563.  
  564.     ostream& operator<<(short n) {return operator<<((int)n);}
  565.     ostream& operator<<(unsigned short n) {return operator<<((unsigned int)n);}
  566.     ostream& operator<<(double n);
  567.     ostream& operator<<(float n) { return operator<<((double)n); }
  568.     ostream& operator<<(__omanip func) { return (*func)(*this); }
  569.     ostream& operator<<(__manip func) {(*func)(*this); return *this;}
  570.     ostream& operator<<(streambuf*);
  571. };
  572.  
  573. class istream : virtual public ios
  574. {
  575.      
  576.     _G_ssize_t _gcount;
  577.  
  578.     int _skip_ws();
  579.   public:
  580.     istream() { _gcount = 0; }
  581.     istream(streambuf* sb, ostream*tied=((void *)0) );
  582.     streambuf* istreambuf() const { return _strbuf; }
  583.     istream& get(char* ptr, int len, char delim = '\n');
  584.     istream& get(unsigned char* ptr, int len, char delim = '\n')
  585.     { return get((char*)ptr, len, delim); }
  586.     istream& get(char& c);
  587.     istream& get(unsigned char& c) { return get((char&)c); }
  588.     istream& getline(char* ptr, int len, char delim = '\n');
  589.     istream& getline(unsigned char* ptr, int len, char delim = '\n')
  590.     { return getline((char*)ptr, len, delim); }
  591.  
  592.     istream& get(signed char& c)  { return get((char&)c); }
  593.     istream& get(signed char* ptr, int len, char delim = '\n')
  594.     { return get((char*)ptr, len, delim); }
  595.     istream& getline(signed char* ptr, int len, char delim = '\n')
  596.     { return getline((char*)ptr, len, delim); }
  597.  
  598.     istream& read(char *ptr, int n);
  599.     istream& read(unsigned char *ptr, int n) { return read((char*)ptr, n); }
  600.  
  601.     istream& read(signed char *ptr, int n) { return read((char*)ptr, n); }
  602.  
  603.     istream& read(void *ptr, int n) { return read((char*)ptr, n); }
  604.      
  605.     istream& get(streambuf& sb, char delim = '\n');
  606.     istream& gets(char **s, char delim = '\n');
  607.     int ipfx(int need) {
  608.     if (!good()) { set(ios::failbit); return 0; }
  609.     if (_tie && (need == 0 || rdbuf()->in_avail() < need)) _tie->flush();
  610.     if (!need && (flags() & ios::skipws)) return _skip_ws();
  611.     return 1;
  612.     }
  613.     int ipfx0() {  
  614.     if (!good()) { set(ios::failbit); return 0; }
  615.     if (_tie) _tie->flush();
  616.     if (flags() & ios::skipws) return _skip_ws();
  617.     return 1;
  618.     }
  619.     int ipfx1() {  
  620.     if (!good()) { set(ios::failbit); return 0; }
  621.     if (_tie && rdbuf()->in_avail() == 0) _tie->flush();
  622.     return 1;
  623.     }
  624.     int get() { if (!ipfx1()) return (-1) ;
  625.         int ch = _strbuf->sbumpc();
  626.         if (ch == (-1) ) set(ios::eofbit);
  627.         return ch; }
  628.     int peek() { if (!ipfx1()) return (-1) ;
  629.         int ch = _strbuf->sgetc();
  630.         if (ch == (-1) ) set(ios::eofbit);
  631.         return ch; }
  632.     _G_ssize_t gcount() { return _gcount; }
  633.     istream& ignore(int n=1, int delim = (-1) );
  634.     istream& seekg(streampos);
  635.     istream& seekg(streamoff, _seek_dir);
  636.     streampos tellg();
  637.     istream& putback(char ch) {
  638.     if (good() && _strbuf->sputbackc(ch) == (-1) ) clear(ios::badbit);
  639.     return *this;}
  640.     istream& unget() {
  641.     if (good() && _strbuf->sungetc() == (-1) ) clear(ios::badbit);
  642.     return *this;}
  643.     istream& scan(const char *format ...);
  644.     istream& vscan(const char *format, _G_va_list args);
  645.  
  646.     istream& unget(char ch) { return putback(ch); }
  647.     int skip(int i);
  648.  
  649.     istream& operator>>(char*);
  650.     istream& operator>>(unsigned char* p) { return operator>>((char*)p); }
  651.  
  652.     istream& operator>>(signed char*p) { return operator>>((char*)p); }
  653.  
  654.     istream& operator>>(char& c);
  655.     istream& operator>>(unsigned char& c) {return operator>>((char&)c);}
  656.  
  657.     istream& operator>>(signed char& c) {return operator>>((char&)c);}
  658.  
  659.     istream& operator>>(int&);
  660.     istream& operator>>(long&);
  661.  
  662.     istream& operator>>(long long&);
  663.  
  664.     istream& operator>>(short&);
  665.     istream& operator>>(unsigned int&);
  666.     istream& operator>>(unsigned long&);
  667.  
  668.     istream& operator>>(unsigned long long&);
  669.  
  670.     istream& operator>>(unsigned short&);
  671.     istream& operator>>(float&);
  672.     istream& operator>>(double&);
  673.     istream& operator>>( __manip func) {(*func)(*this); return *this;}
  674.     istream& operator>>(__imanip func) { return (*func)(*this); }
  675.     istream& operator>>(streambuf*);
  676. };
  677.  
  678. class iostream : public istream, public ostream
  679. {
  680.     _G_ssize_t _gcount;
  681.   public:
  682.     iostream() { _gcount = 0; }
  683.     iostream(streambuf* sb, ostream*tied=((void *)0) );
  684. };
  685.  
  686. extern istream cin;
  687. extern ostream cout, cerr, clog;  
  688.  
  689. struct Iostream_init { } ;   
  690.  
  691. inline ios& dec(ios& i)
  692. { i.setf(ios::dec, ios::dec|ios::hex|ios::oct); return i; }
  693. inline ios& hex(ios& i)
  694. { i.setf(ios::hex, ios::dec|ios::hex|ios::oct); return i; }
  695. inline ios& oct(ios& i)
  696. { i.setf(ios::oct, ios::dec|ios::hex|ios::oct); return i; }
  697.  
  698. # 7 "/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/g++-include/stream.h" 2
  699.  
  700. extern char* form(const char*, ...);
  701.  
  702. extern char* dec(long, int=0);
  703. extern char* dec(int, int=0);
  704. extern char* dec(unsigned long, int=0);
  705. extern char* dec(unsigned int, int=0);
  706.  
  707. extern char* hex(long, int=0);
  708. extern char* hex(int, int=0);
  709. extern char* hex(unsigned long, int=0);
  710. extern char* hex(unsigned int, int=0);
  711.  
  712. extern char* oct(long, int=0);
  713. extern char* oct(int, int=0);
  714. extern char* oct(unsigned long, int=0);
  715. extern char* oct(unsigned int, int=0);
  716.  
  717. inline istream& WS(istream& str) { return ws(str); }
  718.  
  719. # 2 "foo.cc" 2
  720.  
  721. class myclass
  722. {
  723.   int myelem;
  724. public:
  725.   myclass() {myelem = 0;};
  726.   ~myclass() {cout << "deleted" << '\n';};
  727.  
  728.   void * operator new(size_t s) {cout << "allocating " << s << " bytes\n";return malloc(s);};
  729.   void operator delete(void *p, size_t s) {cout << "deleting " << s << " bytes\n";free(p);};
  730. };
  731.  
  732. main()
  733. {
  734.   myclass *p = new myclass; /* should use the class member function */
  735.   myclass *a = new myclass[50]; /* should go through default */
  736.   
  737.   delete p;
  738.   delete a;
  739. }
  740.  
  741. /*
  742.  
  743. The above code was obtained from g++-2.3.3
  744. Running on a sparc station running sun-os-4.1
  745. configure was given these parameters
  746.  
  747. The following output was obtained from the program
  748.  
  749. almer.47% g++ foo.i
  750. almer.47% a.out
  751. allocating 4 bytes
  752. allocating 208 bytes
  753. deleted
  754. deleting 4 bytes
  755. deleted
  756. deleting 4 bytes
  757. almer.48% 
  758.  
  759. The output I would expect would be
  760.  
  761. % a.out
  762. allocating 4 bytes
  763. deleted
  764. deleting 4 bytes
  765. deleted
  766. .
  767. . /* repeat 207 times */
  768. .
  769.  
  770. I haven't looked at the compiler internals to see what is going on, it
  771. took me a long time to figure out what was going on in the program I
  772. was using!
  773.  
  774. Hope this is of help
  775.  
  776. Cheers
  777. Hamish Fallside
  778.  
  779. */
  780.  
  781.