GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 09-Sep-2008, 23:46
mckarvin mckarvin is offline
New Member
 
Join Date: Sep 2008
Posts: 1
mckarvin is on a distinguished road

Segmentation error in C++ code


Hi,

I am getting segmentation error in C++ code....please help me out in solving this.. I have indicated the error creating parts in red


CPP / C++ / C Code:
int main (int argc, char **argv)
{
   Arg("AWsize", AWsize, 2);
   Arg("queuelimit", queuelimit, 30); 
   
//[color="Red"]   
Arg::ProcessArgs(argc,argv);
   if (Arg::Specified("trace"))
   {
     std::cout<< "trace is specified" << std::endl;
   }
   std::cout << "Advertised window size specified is " << AWsize << " packets" << std::endl;
   std::cout << "Queue limit specified is " << queuelimit << " packets" << std::endl;
    
   AWsize = AWsize * 8; //window size converted from packets to bytes

   Validation::Init(argc,argv);
   Simulator s;

//[/color]   

Trace* tr = Trace::Instance();
   Queue* qu;
   tr->IPDotted(true);
   tr->Open("assign1.txt");
   TCP::LogFlagsText(true);
   IPV4::Instance()->SetTrace(Trace::ENABLED);

   TCP* a;

   Node* c1 = new Node();
   Node* s1 = new Node();
   Node* r1 = new Node();
   Node* r2 = new Node();

   c1->SetLocation(0,0);
   s1->SetLocation(4,0);
   r1->SetLocation(1,0);
   r2->SetLocation(3,0);

#ifdef HAVE_QT
  c1->Color(Qt::blue);
  s1->Color(Qt::blue);
  r1->Color(Qt::red);
  r2->Color(Qt::red);
#endif
   Linkp2p l(Rate("10Mb"), Time("10ms"));

   c1->AddDuplexLink(r1, l, IPAddr("192.168.0.1"));
   s1->AddDuplexLink(r2, l, IPAddr("192.168.0.2"));

   Linkp2p r(Rate("1Mb"), Time("10ms"));

   r2->AddDuplexLink(r1, r);

//segmentation error occurs while executing the code shown below.
//[color="Red"]
   a->SetAdvertisedWindow(16);
   qu->DefaultLimitPkts(30);
   qu->Animate(true);
//[/color]
 }
Last edited by LuciWiz : 10-Sep-2008 at 00:32. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
  #2  
Old 10-Sep-2008, 01:31
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Segmentation error in C++ code


Why don't you post something complete enough for us to compile and get the segfault too.
  #3  
Old 10-Sep-2008, 05:31
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Segmentation error in C++ code


I see two pointers declared:
CPP / C++ / C Code:
   Queue* qu;
   TCP* a;
...but where are these initialized before their use here:
CPP / C++ / C Code:
a->SetAdvertisedWindow(16);
qu->DefaultLimitPkts(30);
qu->Animate(true);
I would suspect that 'a' and 'qu' have garbage values, and thus, are invalid pointers -- and possibly causing the segfault.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble integrating console code into GUI Barman007 Java Forum 18 15-May-2008 14:05
How to sort random access file? wmmccoy0910 C Programming Language 12 04-Sep-2006 04:40
Here it is again! 35% - 40% off For Life! my-e-space Web Hosting Advertisements & Offers 0 20-Apr-2006 15:48
Segmentation error on executing socket code nkhambal C Programming Language 3 30-Aug-2004 13:53

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:52.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.