hello all,
could someone explain to why segmentation fault and memore fault would occur.
what is the difference between the two any way?
tnx
Printable View
hello all,
could someone explain to why segmentation fault and memore fault would occur.
what is the difference between the two any way?
tnx
Segmentation faults are when you usually screw up with pointers.
A memory fault is when you screw up and forget your significant other's birthday, your anniversary, etc, and they kill you for it.
Quzah.
Try to do the following and you will know the answer.
1.) Try to free an already freed memory.
2.) alloc () "n" (n= some number) of memory, get your pointer to point to outside the boundary of n and then try free' ing it.
3.) alloc some memory inside a function called from, lets say main() and don't delete it. Try to access the memory from main now.
Anoop.
> 3.) alloc some memory inside a function called from, lets say
> main() and don't delete it. Try to access the memory from main
> now.
To access it, you would have to know where it was. If you knew
where it was, you'd have its addressed. If you had its address,
then you can make a pointer to it.
Since this is 'alloc'ed memory (malloc/realloc/calloc), any function
that has a pointer to its memory address, can access it without
any problems.
Quzah.
>> 3.) alloc some memory inside a function called from, lets say
>> main() and don't delete it. Try to access the memory from >main
>> now.
>To access it, you would have to know where it was. If you knew
>where it was, you'd have its addressed. If you had its address,
>then you can make a pointer to it.
>Since this is 'alloc'ed memory (malloc/realloc/calloc), any function
>that has a pointer to its memory address, can access it without
>any problems.
My bad.
3.) should have been
void main ()
{
...
...
int *ptr;
func(ptr);
....
//try using ptr now.
}
func (ptr)
{
int i = 2;
....
ptr = &i;
....
}
I don't know, something about that little snippet makes me cringe. Let's try it again, but correctly this time.Quote:
3.) should have been
void main ()
{
For some odd reson people trust your answers more if you actually know what you're doing and can show it through your code. Using void main is a dead giveaway.Code:3.) should have been
int main ( void )
{
-Prelude
Okay let me be absolutely ANSI correct.
It should be
int main()
No, it shouldn't. If you were absolutely ANSI correct then you would write code exactly as the standard tells you to. The ANSI/ISO standard EXPLICITY states that when main has no arguments it is declared asQuote:
Okay let me be absolutely ANSI correct.
It should be
int main()
int main ( void )
Which is close to yours, but not exactly, which is why you're wrong. And I'm going to go away and come back when I'm in a better mood, before everyone starts to hate me.
-Prelude
Looks like today is not my day :(
int main(void)
int main(void)
int main(void)
int main(void)
int main(void)
int main(void)
int main(void)
int main(void)
int main(void)
int main(void)
Thanks,
Anoop.
:D Unfortunately there is a problem...Quote:
Looks like today is not my day
int main(void)
int main(void)
int main(void)
int main(void)
int main(void)
int main(void)
int main(void)
int main(void)
int main(void)
int main(void)
There can only be ONE MAIN FUNCTION! HAHAHA... Oh, I slay me. :D :D
Quzah.
Hehe, good one :)
-Prelude
Today is a new day and boy am I feeling fresh?
>>There can only be ONE MAIN FUNCTION! HAHAHA... Oh, I slay me.
Well not exactly. there can be only one main function not MAIN ;)
hahhahahaa
I have never heard of a "memore fault". On unix a segfault means that you have dereferanced an address that is invalid or that you don't have rights to.