Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: Segmentation Fault

Started 1 month, 3 weeks ago by DanMD
Hey guys, had a quick question for you. Suppose you had a function such as: char * hullo() { char * h = "hullo"; return h; } int main() { char * wee = hullo(); delete wee; <-- Segmentation fault return 0; } I wouldn't really want to do anything like this, I'd rather pass in a pointer to the hullo function. However, if you were to...
Site: CodeGuru Forums - A Developer.com Community for C++, C#, VB, Java and .NET Solutions  CodeGuru Forums - A Developer.com Community for C++, C#, VB, Java and .NET Solutions - site profile
Forum: C++ (Non Visual C++ Issues)  C++ (Non Visual C++ Issues) - forum profile
Total authors: 4 authors
Total thread posts: 5 posts
Thread activity: no new posts during last week
Domain info for: codeguru.com

Other posts in this thread:

pi3orama replied 1 month, 3 weeks ago
String "hullo" should reside in data section, the memory is allocated when the program loaded and never and needn't be free, because it has only 1 copy during the program execution. You can try to modify the string: wee[1] = '\0'; you should receive a SEGFAULT because it in data section and readonly. If you look at the address of "hullo", you should find that it is 0x08xxxxxx, very ...

Lindley replied 1 month, 3 weeks ago
1) Every new must be matched with a delete (and new[]/delete[], and malloc/free). 2) If there is no new/new[]/malloc/calloc, then there is no need to explicitly free anything.

DanMD replied 1 month, 3 weeks ago
ah I see, so it was never on the heap in the first place? I was under the impression declaring a string like this: char * hullo = "hello"; called malloc, but I guess not , just gave it a try malloc'ing the string and this time no seg fault. Thanks guys

potatoCode replied 1 month, 3 weeks ago
Quote: Originally Posted by pi3orama String "hullo" should reside in data section, if it should, where does it usually reside then? Quote: the memory is allocated when the program loaded and never and needn't be free, I assume that is to ensure the application you ...

 

Top contributing authors

Name
Posts
DanMD
2
user's latest post:
Segmentation Fault
Published (2009-11-06 01:36:00)
ah I see, so it was never on the heap in the first place? I was under the impression declaring a string like this: char * hullo = &quot;hello&quot;; called malloc, but I guess not , just gave it a try malloc'ing the string and this time no seg fault. Thanks guys
pi3orama
1
user's latest post:
Segmentation Fault
Published (2009-11-05 23:21:00)
String &quot;hullo&quot; should reside in data section, the memory is allocated when the program loaded and never and needn't be free, because it has only 1 copy during the program execution. You can try to modify the string: wee[1] = '\0'; you should receive a SEGFAULT because it in data section and readonly. If you look at the address of &quot;hullo&quot;, you should find that it is 0x08xxxxxx, very close the...
Lindley
1
user's latest post:
Segmentation Fault
Published (2009-11-06 00:14:00)
1) Every new must be matched with a delete (and new[]/delete[], and malloc/free). 2) If there is no new/new[]/malloc/calloc, then there is no need to explicitly free anything.
potatoCode
1
user's latest post:
Segmentation Fault
Published (2009-11-06 02:08:00)
Quote: Originally Posted by pi3orama String &quot;hullo&quot; should reside in data section, if it should, where does it usually reside then? Quote: the memory is allocated when the program loaded and never and needn't be free, I assume that is to ensure the application you made hogs all the system resource, correct? I mean, why share, right? Quote: because it has only 1 copy during the program execution. so that this string...

Related threads on "CodeGuru Forums - A Developer.com Community for C++, C#, VB, Java and .NET Solutions":

Related threads on other sites:

Thread profile page for "Segmentation Fault" on http://www.codeguru.com. This report page is a snippet summary view from a single thread "Segmentation Fault", located on the Message Board at http://www.codeguru.com. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity