The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Why not a segmentation fault?? lagigliaivan High Level Programming 22 05-21-2008 08:07 AM
segmentation fault rockgal High Level Programming 8 12-05-2006 09:16 AM
Segmentation Fault compbug UNIX for Dummies Questions & Answers 3 04-21-2006 07:43 AM
Segmentation fault jshaulis AIX 1 06-01-2004 01:16 PM
segmentation fault omran High Level Programming 2 08-01-2003 05:19 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-19-2005
Registered User
 

Join Date: Feb 2005
Posts: 40
segmentation fault

sometimes for this code i get a segmentation fault for codes llike this

:

int main{
int * a= 0;
int b;
a = (int*)malloc(sizeof(int));
///some code using these variable but no freeing of a

if(a){
free(a);
a = 0;
}
return 0;
}
Reply With Quote
Forum Sponsor
  #2  
Old 02-19-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,663
The problem is probably in the code you did not post. But I will mention that malloc will fail if the data segment has maxed out. I don't see you test for that. You'll get a null pointer with errno set to ENOMEM. Dereferencing a null pointer can cause a seg fault on some architectures.
Reply With Quote
  #3  
Old 02-19-2005
Registered User
 

Join Date: Feb 2005
Posts: 40
thank you

thanks buddy your a gr8 help but will trouble you later for more queries .for now have this one.which is the command which asks the system to wait for some time(say millisec)before printing some statement
eg
something like this
waiting . . . . .

code is
int i;
for(i =0;i < 10;i++){
printf(" .");
//command i'm loooking which waits for(say 300 ms) (works in linux not windows)
}
printf("\n");


plz reply thanx
Reply With Quote
  #4  
Old 02-19-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,663
See: nodoff sleep for less than a second
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 02:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0