3 ms·
"warning: initialization makes integer from pointer without a cast" I mean sure, there are warnings and there are warnings. Absurdist pedantry about warning s
by ajross 13y ago
"warning: initialization makes integer from pointer without a cast"
I mean sure, there are warnings and there are warnings. Absurdist pedantry about warning states isn't something I tend to worry about.
But if you're dealing with a code base that is building to completion without attention to this warning (which pops out with the default flags on gcc 4.7.2 -- no -Wall needed!), then you have more serious problems than can be fixed by a builtin pointer-to-bool conversion.
- ben0x539 13y agoArguably that warning just suggests that you put in a cast, which makes it no more correct. Then you get another warning "cast from pointer to integer of different size [-Wpointer-to-int-cast]" which apparently is also on by default, but I'm not sure it's immediately obvious to a casual C programmer how that will go wrong.
- ajross 13y agoAgain, I'd argue that if you have a programmer willing to throw in a double cast expression (!) to work around a warning without once thinking about what they are trying to do (in this case to check if a pointer is NULL) then you have problems that aren't going to be well addressed by a C99 bool anyway. I mean, this example is a little contrived as it is. The "normal" way to treat a pointer as a boolean and branch off of it is just "if(ptr)", and that's worked without trouble on all compilers for 40 years now. Is C sort of a mess? Yeah. But this isn't a particularly illustrative example IMHO. All languages have this nonsense (c.f. the Ruby/JS "Wat" video).
- EpicEng 13y agoNo it doesn't. Not to anyone who knows C anyway.
- mtdewcmu 13y agoCasting pointers to integers isn't all that common to do. When I see that warning, I take it very seriously, because it almost always means I made a real mistake.
- nknighthb 13y agoIt's gotten better the last few years, but I still see that exact warning all the time in open-source projects. Nobody cares about warnings until someone mandates -Werror.
- crest 13y agoCFLAGS+=-Wall -Wextra -pedantic -Werror # have fun