This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: cpplib and a couple others: squelch -pedantic warnings
- To: Zack Weinberg <zack at wolery dot cumb dot org>
- Subject: Re: cpplib and a couple others: squelch -pedantic warnings
- From: Gabriel Dos Reis <gdr at codesourcery dot com>
- Date: 04 May 2000 20:32:21 +0200
- Cc: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>, gcc-patches at gcc dot gnu dot org, jason at cygnus dot com
- Organization: CodeSourcery, LLC
- References: <200005041735.NAA02657@caip.rutgers.edu> <20000504112141.O281@wolery.cumb.org>
Zack Weinberg <zack@wolery.cumb.org> writes:
[...]
| > However I'm not sure why its necessary to make malloc'ed objects be
| > const char *. Sometimes its done when you share malloc'ed strings and
| > "literal" and/or const strings in the same pointer. IMHO, this is a
| > dangerous practice because it leads to strange errors when you
| > accidentally free the "literal" string. Would it be possible to stop
| > malloc'ing strings into const char * pointers in cpp without
| > de-constifying it too much?
|
| Actually, malloced strings are the least of the problem.
|
| Most of cpplib's data structures are write-once. I express that by
| building them in non-constant variables, then setting constant
| pointers to them. The compiler can then enforce immutability
| everywhere else. I've found several subtle and dangerous bugs with
| this tactic. But I still need the ability to free those data
| structures when I'm done with them.
That is the sort of thing what I'm doing with the diagnostic stuff.
I don't find de-constifying the right thing to do, at least not as
proposed.
-- Gaby
CodeSourcery, LLC http://www.codesourcery.com