开发者

GCC, functions, and pointer arguments, warning behaviour

开发者 https://www.devze.com 2023-01-01 20:46 出处:网络
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 ho

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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号