This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: cpplib and a couple others: squelch -pedantic warnings


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]