The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 11:07 AM
segmentation fault rockgal High Level Programming 8 12-05-2006 12:16 PM
Segmentation Fault compbug UNIX for Dummies Questions & Answers 3 04-21-2006 10:43 AM
Segmentation fault jshaulis AIX 1 06-01-2004 04:16 PM
segmentation fault omran High Level Programming 2 08-01-2003 08:19 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-19-2005
wojtyla wojtyla is offline
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;
}
  #2 (permalink)  
Old 02-19-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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.
  #3 (permalink)  
Old 02-19-2005
wojtyla wojtyla is offline
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
  #4 (permalink)  
Old 02-19-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
See: nodoff sleep for less than a second
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes 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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0