2 Replies - 1326 Views - Last Post: 22 May 2008 - 12:42 AM Rate Topic: -----

#1 Sepanto   User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 20-March 08

Bus error.

Posted 21 May 2008 - 02:01 PM

Hi guys. I'm writing a program, whcih gives me a bus error when compiled under g++. would anyone mind telling me why. the bus error is given when initialising the program, never gettign to menuManager() method in the end of interface costructor.
#include "Interface.h"
#include <iostream>
using namespace std;
int main()
{
	cout<<2;
	Interface *i1=new Interface();
	return 0;
}



using namespace std;
Interface::Interface()
{	
	numberOfCenters=0;
	numberOfChains=0;
	Chains=NULL;
	Centers=NULL;
	cout<<-3;
	addCenter("Hilel",212);
	cout<<-4;
	addCenter("Hasharon",432);
	cout<<-5;
	addChainClothing("Bastro","Moshe");
	cout<<-6;
	addChainFood("Columbus",3);
	addChainFastFood("George",3,25,35);
	 cout<<-1;
	addChainBook("Shuper","C++ programming is fun");
	 cout<<-2;
	Chains[0]->addShop(2);
	Chains[1]->addShop(12);
	 cout<<0<< endl;
	Chains[2]->addShop(43);
	 cout<<1<< endl;
	Chains[3]->addShop(65);
	 cout<<2<< endl;
	 cout<<"Finished initializing"<< endl;
	Centers[0]->addChainToMall(Chains[0]);
	Centers[0]->addShop(Chains[0]->getShop(2));
	 cout<<3<< endl;
	Centers[0]->addChainToMall(Chains[2]);
	Centers[0]->addShop(Chains[2]->getShop(43));
	 cout<<4<< endl;
	Centers[1]->addChainToMall(Chains[1]);
	Centers[1]->addShop(Chains[1]->getShop(12));
	 cout<<5<< endl;
	Centers[1]->addChainToMall(Chains[3]);
	Centers[1]->addShop(Chains[3]->getShop(65));
	 cout<<6<< endl;
	menuManager();
}


void Interface::addCenter(const char* name,int number)
{
int j,place;
if(findCenter(name,number)==-1)
	{
		place=findPlaceNewCenter(number);
		Center** tempo=Centers;
		Centers= new Center* [++numberOfCenters];
		for (j=0;j<numberOfCenters-1;j++)
			if(j!=place)
				Centers[j]=tempo[j];
		Centers[place]= new Center(number,name);
		delete []tempo;
	}
else 
 cout<<"not unique error"<< endl;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Bus error.

#2 perfectly.insane   User is offline

  • D.I.C Addict
  • member icon

Reputation: 70
  • View blog
  • Posts: 644
  • Joined: 22-March 08

Re: Bus error.

Posted 21 May 2008 - 04:51 PM

I think we would need to see [more of] your code, but in general, a bus error is likely to be caused by improperly aligned access to a memory area. For example, if you have an int, which is 4 bytes, you probably can't dereference an int pointer who's pointer value is odd (it likely needs to be in multiples of 2 or 4). The rules are machine-dependent. This would happen when casting a byte pointer type (such as char*) to a type of a larger access width (int*).
Was This Post Helpful? 0
  • +
  • -

#3 Sepanto   User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 20-March 08

Re: Bus error.

Posted 22 May 2008 - 12:42 AM

What more code do you need?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1