This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

I guess it IS a bug


Hi,
When I try to compile the attched file: bstream.c bstream.h, I got some
compilation error with which I'm confused. I've tried to compile the code
on some other machines using other c++ compiler. And there is nothing
wrong with it.
Could you please have a look of it and reply me as soon as possible? Thx.

egcs version:	egcs-1.1.2-12, egcs-c++-1.1.2-12 (from RH6.0 package)
system type:	Linux (RH6.0) with kernel 2.2.5-15
command line:	g++ -c bstream.c
preprocessed:	bstream.ii (as attached)
		(g++ -v --save-temps -c bstream.c)

best regards,
zy
************************************************************************
Name	:  Zhang Yi 
URL	:  http://www.comp.nus.edu.sg/~zhangy
Office	:  S15 #05-22
Phone	:  (65) 874-6803/4362
Email	:  zhangy@comp.nus.edu.sg OR dcszy@nus.edu.sg
Mail	:  Zhang Yi, School of Computing, 
	   National University of Singapore, Kent Ridge, S(119260)
************************************************************************
/* ************* BSTREAM.C   Bitstream file i/o class ***********
 * ****************** By Alexis 'Milamber' Ashley *************** 
 *
 * Copyright (C) 1995 Alexis Ashley          milamber@dcs.warwick.ac.uk
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "bstream.h"
#include <assert.h>

void ibstream::open(const char *name, int mode,int prot)
{
  ifstream::open(name,mode,prot);
  if(good())
    _is_open=true;
  reset_count();
}

ibstream& ibstream::BitRead(long int &value,int bits)
{
  assert(bits>0 && bits<33);
  value=0;
  for(int i=0; i<bits; i++)
    {
      value <<= 1;
      if(power==0)
	{
	  ifstream::read(&val,1);
	  power=128;
	}
      if((val & power)!=0)
	{
	  value |= 1;
	}
      power >>= 1;
    }
  return *this;
}

ibstream& ibstream::FlushRead(void)
{
  reset_count();
  return *this;
}

ibstream& ibstream::seekg(streampos pos)
{
  reset_count();
  ifstream::seekg(pos);
}

ibstream& ibstream::seekg(streamoff pos, seek_dir sd)
{
  reset_count();
  ifstream::seekg(pos,sd);
}

ibstream& ibstream::BitSeekg(long int pos, int bitpos)
{
  long val;

  assert(bitpos>=0);
  reset_count();
  pos += bitpos / 8;
  bitpos %= 8;
  ifstream::seekg(pos);
  if(bitpos)
    BitRead(val,bitpos);
  return *this;
}

void obstream::open(const char *name, int mode,int prot)
{
  ofstream::open(name,mode,prot);
  if(good())
    _is_open=true;
  reset_count();
}

obstream& obstream::BitWrite(long int value, int bits)
{
  assert(bits>0 && bits<33);
  value = value << 32-bits;
  for(int i=0; i<bits; i++)
    {
      if((value & 0x80000000)!=0)
	val += power;
      value = (value & 0x7FFFFFFF) << 1;
      power >>= 1;
      if(power==0)
	{
	  ofstream::write((unsigned char *)&val,1);
	  reset_count();
	}
    }
  return *this;
}

obstream& obstream::FlushWrite(void)
{
  if(power!=128)
    {
      ofstream::write(&val,1);
      reset_count();
    }
  return *this;
}

obstream& obstream::seekp(streampos pos)
{
  assert(pos>0);
  FlushWrite();
  ofstream::seekp(pos);
  reset_count();
  return *this;
}

obstream& obstream::seekp(streamoff pos, seek_dir sd)
{
  FlushWrite();
  ofstream::seekp(pos,sd);
  reset_count();
  return *this;
}

void bstream::open(const char *name, int mode,int prot)
{
  ibstream::open(name,mode,prot);
  obstream::open(name,mode,prot);
}
/* ************* BSTREAM.H   Bitstream file i/o class ***********
 * ****************** By Alexis 'Milamber' Ashley *************** 
 *
 * Copyright (C) 1995 Alexis Ashley          milamber@dcs.warwick.ac.uk
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef __BSTREAM__
#define __BSTREAM__

#include <assert.h>
#include <fstream.h>
#include "typedefs.h"

class ibstream : public virtual ifstream
{
public:
  ibstream(void)
    {
      _is_open = false;
    }
  ~ibstream(void)
    {
    }
  void open(const char *name, int mode=(ios::in | ios::nocreate),
	    int prot=0664);
  void close(void)
    {
      _is_open=false;
      ifstream::close();
    }
  int is_open(void) const
    {
      return _is_open;
    }
  ibstream& BitRead(long &val, int bits);
  ibstream& read(char *buff, int count)
    {
      assert(buff!=NULL);
      assert(_is_open);
      ifstream::read(buff,count);
      reset_count();
      return *this;
    }
  ibstream& read(unsigned char *buff, int count)
    {
      assert(buff!=NULL);
      assert(_is_open);
      ifstream::read(buff,count);
      reset_count();
      return *this;
    }
  ibstream& read(void *buff, int count)
    {
      assert(buff!=NULL);
      assert(_is_open);
      ifstream::read(buff,count);
      reset_count();
      return *this;
    }
  ibstream& FlushRead(void);
  ibstream& seekg(streampos);
  ibstream& seekg(streamoff,seek_dir);
  ibstream& BitSeekg(long pos, int bitpos);
protected:
  void reset_count(void)
    {
      power=0;
      val=0;
    }
private:
  bool _is_open;
  int power;
  unsigned char val;
};

class obstream : public virtual ofstream
{
public:
  obstream(void)
    {
      _is_open = false;
    }
  ~obstream(void)
    {
    }
  void open(const char *name, int mode=ios::out, int prot=0664);
  void close(void)
    {
      _is_open=false;
      ofstream::close();
    }
  obstream& BitWrite(long val, int bits);
  obstream& write(char *buff, int count)
    {
      assert(buff!=NULL);
      assert(_is_open);
      if(power!=128)
	FlushWrite();
      ofstream::write(buff,count);
      reset_count();
      return *this;
    }
  obstream& write(unsigned char *buff, int count)
    {
      assert(buff!=NULL);
      assert(_is_open);
      if(power!=128)
	FlushWrite();
      ofstream::write(buff,count);
      reset_count();
      return *this;
    }
  obstream& write(void *buff, int count)
    {
      assert(buff!=NULL);
      assert(_is_open);
      if(power!=128)
	FlushWrite();
      ofstream::write(buff,count);
      reset_count();
      return *this;
    }
  obstream& FlushWrite(void);
  obstream& seekp(streampos);
  obstream& seekp(streamoff, seek_dir);
protected:
  void reset_count(void)
    {
      power=128;
      val=0;
    }
private:
  bool _is_open;
  int power;
  unsigned char val;
};

class bstream : public ibstream, obstream
{
public:
  bstream(void)
    {
    }
  ~bstream(void)
    {
    }
  void open(const char *name, int mode, int prot=0664);
private:
};

#endif


bstream.ii.gz


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]