473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Segmentation fault problem

Hi all,

I wrote a SystemC program which was compiled fine with g++, but as run, I got a segmentation fault:
Program received signal SIGSEGV, Segmentation fault.
0x0804a720 in mpsoc (n_slave=2) at ./src/main.cpp:149
149 router_mapfile << slave_array[i]->name() << endl;

The fault is located on this line router_mapfile << slave_array[i]->name() << endl; I attached the part of my code following, could anyone please help me figure it out. Thanks in anticipation.


vector<slave_cpu*> slave_array(n_slave);

for (i = 0; i < n_slave; i++)
{
slave_cpu slave(sc_module_name(sc_gen_unique_name("slave_cpu ")), SLAVE_REG);
slave_array.push_back(&slave);
}

/*generate the router port mapping file according the argument n_slave*/
ofstream router_mapfile("master.iport.map");

if ( ! router_mapfile ) { /*open failed*/
cerr << "cannot open master.iport.map for writing router port mapping" << endl;
exit(-1);
}
else {
cout << "generating the router port mapping file master.iport.map" << endl;
}
for (i = 0; i < n_slave; i++)
{
router_mapfile << slave_array[i]->name() << endl;
}
Nov 29 '06 #1
1 1949
horace1
1,510 Expert 1GB
try replacing
Expand|Select|Wrap|Line Numbers
  1. vector<slave_cpu*>    slave_array(n_slave);
  2.  
with
Expand|Select|Wrap|Line Numbers
  1. vector<slave_cpu*>    slave_array;
  2.  
also I think your loop
Expand|Select|Wrap|Line Numbers
  1. for (i = 0; i < n_slave; i++)
  2.     { 
  3.     slave_cpu slave(sc_module_name(sc_gen_unique_name("slave_cpu")), SLAVE_REG);
  4.      slave_array.push_back(&slave);
  5.     }
  6.  
should be
Expand|Select|Wrap|Line Numbers
  1. for (i = 0; i < n_slave; i++)
  2.     { 
  3.     slave_cpu * slave = new slave_cpu(sc_module_name(sc_gen_unique_name("slave_cpu")), SLAVE_REG);
  4.      slave_array.push_back(slave);
  5.     }
  6.  
Nov 29 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: sivignon | last post by:
Hi, I'm writing a php script which deals with 3 ORACLE databases. This script is launch by a script shell on an linux machine like this : /../php/bin/php ./MySript.php (PHP 4.3.3) My script...
3
by: diyanat | last post by:
i am writing a cgi script in C using the CGIC library, the script fails to run, i am using apache on linux error report from apache : internal server error Premature end of script headers:...
16
by: laberth | last post by:
I've got a segmentation fault on a calloc and I don'tunderstand why? Here is what I use : typedef struct noeud { int val; struct noeud *fgauche; struct noeud *fdroit; } *arbre; //for those...
6
by: damian birchler | last post by:
If I run the following I get a segmentation fault: #define NAMELEN 15 #define NPERS 10 typedef struct pers { char name; int money; } pers_t;
3
by: Zheng Da | last post by:
Program received signal SIGSEGV, Segmentation fault. 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 (gdb) bt #0 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 #1 0x40094c54 in malloc...
5
by: Fra-it | last post by:
Hi everybody, I'm trying to make the following code running properly, but I can't get rid of the "SEGMENTATION FAULT" error message when executing. Reading some messages posted earlier, I...
27
by: Paminu | last post by:
I have a wierd problem. In my main function I print "test" as the first thing. But if I run the call to node_alloc AFTER the printf call I get a segmentation fault and test is not printed! ...
3
by: madunix | last post by:
My Server is suffering bad lag (High Utlization) I am running on that server Oracle10g with apache_1.3.35/ php-4.4.2 Web visitors retrieve data from the web by php calls through oci cobnnection...
8
by: Bryan | last post by:
Hello all. I'm fairly new to c++. I've written several programs using std::vectors, and they've always worked just fine. Until today. The following is a snippet of my code (sorry, can't...
3
by: jr.freester | last post by:
I have created to classes Matrix and System. System is made up of type matrix. ---------------------------------------------------------------------------------- class Matrix { private: int...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.