1

I've recently updated to a testing distribution, which is now using GCC 4.4.3. Now I've set everything up, I've returned to coding and have built my project and I get one of these horrible messages:

*** glibc detected *** ./boxyseq: free(): invalid pointer: 0x0000000001d873e8 ***

I absolutely know what is wrong here, but was rather confused as to when I saw my C code where I call a function which frees a dynamically allocated data structure - I had passed it an incompatible pointer type - a pointer to a completely different data structure.

warning: passing argument 1 of 'data_A_free' from incompatible pointer type
note: expected 'struct data_A *' but argument is of type 'struct data_B *'

I'm confused because I'm sure this would have been an error before and compilation would never have completed. Is this not just going to make life more difficult for C programmers?

Can I change it back to an error without making a whole bunch of other warnings errors too?

Or am I loosing the plot and it's always been a warning?

4
  • I'll delete this question if it's always been a warning! Commented Jun 3, 2010 at 8:02
  • if you know how to make this in particular an error, please post. It's covered by -pedantic-errors, but that's broader. Commented Jun 3, 2010 at 8:06
  • @Matthew so it has always been a warning? If I find out I'll post, but a quick search through gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/Warning-Options.html didn't reveal anything. Commented Jun 3, 2010 at 8:10
  • No, I don't know about that either. Commented Jun 3, 2010 at 8:13

2 Answers 2

2

It's always been a warning. C allows you to implicitly cast any pointer to any other pointer, although any half-decent compiler will warn you.

It's an error in C++, though. Perhaps that's what you were thinking of?

In GCC, you can turn a warning into an error using -Werror=, but I don't see an option for this particular warning. You could just use -Werror to turn all warnings into errors, but that might do more than you want.

Sign up to request clarification or add additional context in comments.

Comments

0

This is definitely one of the things that the clang analyzer would catch, and therefore you can make it an error building with clang.

2 Comments

You can make it an error with gcc too (-pedantic-errors). The question is can you avoid making a bunch of other warnings errors.
Eurrgghh, just read the wikipedia page about it: "Its goal is to offer a replacement to the GNU Compiler Collection (GCC). Development is sponsored by Apple..." no thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.