hello all,
could someone explain to why segmentation fault and memore fault would occur.
what is the difference between the two any way?
tnx
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.
Hope is the first step on the road to disappointment.
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.
Hope is the first step on the road to disappointment.
>> 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.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
My best code is written with the delete key.
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 asOkay 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
My best code is written with the delete key.
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.
Unfortunately there is a problem...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.
Quzah.
Hope is the first step on the road to disappointment.
Hehe, good one
-Prelude
My best code is written with the delete key.
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.