Click here to Skip to main content
15,911,039 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I'm just wondering if I have to call free() on a const char * pointer or string (idk which one it is). The reason why I'm wondering this is because of the *, which would seem to imply that it's a pointer. This is how I do it:

const char * filenames[2] = {"file1.png", "file2.png"};


Thanks in advance for any and all replies! -B
Posted

No, not in this case as the memory was not dynamically allocated using malloc and friends :)

Freeing it would be an error ...

Regards
Espen Harlinn
 
Share this answer
 
Comments
Henry Minute 26-Feb-11 11:51am    
I'm glad someone gave correct information.
I can leave my, possibly, ill advised attempt at humour now.

My 5
Espen Harlinn 26-Feb-11 12:17pm    
Thanks Henry!
Sergey Alexandrovich Kryukov 26-Feb-11 11:55am    
Correct, my 5. The answer should be more simple I thing; see mine.
--SA
Espen Harlinn 26-Feb-11 12:18pm    
Thanks SAKryukov!
fjdiewornncalwe 26-Feb-11 11:58am    
Absolutely correct. +5. I've encountered many a developer who has caused themselves issues with this.
No new — no delete. In the same way, no malloc (or calloc or realloc) — no free. Isn't that simple?

—SA
P.S.: Thanks again, CPallini
 
Share this answer
 
v3
Comments
CPallini 26-Feb-11 12:11pm    
Good, my 5. However it should be "no malloc (or calloc or realloc) -> no free".
Sergey Alexandrovich Kryukov 26-Feb-11 12:41pm    
Oh, my bad; I messed up -- will fix it.
Thanks a lot.
--SA
Espen Harlinn 26-Feb-11 12:51pm    
Well, yes - my 5
Sergey Alexandrovich Kryukov 26-Feb-11 14:36pm    
Thank you, credit to CPallini.
--SA
Free the filenames[2]!

Please feel free to to ignore this posting. :-O
 
Share this answer
 
Comments
CPallini 26-Feb-11 12:52pm    
free(Henry); :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900