This is the mail archive of the gcc-help@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]
Other format: [Raw text]

RE: can't disable pointer-to-int-cast warnings


> > Compiled with this commandline:
> > gcc -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -c foo.c
> >
> > produces the following (approximate) output with GCC 4.3.5, 4.4.4,
> 4.5.1, and 4.6 RC2, regardless of optimization level:
> > foo.c: In function 'main':
> > foo.c:13:2: warning: passing argument 1 of 'f' makes integer from
> pointer without a cast [enabled by default]
> > foo.c:5:6: note: expected 'intptr_t' but argument is of type 'char *'

> It's not obviously a bug, those options work as documented.
> 
> Those warning options relate to casts between pointers and integers of
> different sizes.  There is no cast in your example (only an implicit
> conversion) and intptr_t is not a different size to a pointer.

You're correct, of course. Unfortunately, it only tells me "[enabled by default]", rather than a specific option, so I had to go hunting for warnings that sounded relevant. Is it a bug that GCC didn't tell me what specific option enabled the warning? Or, is it a bug/missing feature that it's an intrinsic warning that can't ever be disabled?

Do you know what option and/or pragma *would* disable the specific warning mentioned above on the code previously sent? I tried -Wno-conversion, and disabling Wconversion via pragma, along with several others. I was hoping for help from gcc-help, after all :)

> Adding a cast (to an integer the same size as a pointer) will stop the
> warning:
>     f((intptr_t)name);

Obviously. In the real example, this is an issue in a variadic argument macro expansion, where there doesn't appear to be a way to explicitly cast each of the individual arguments supplied (beyond the the first) to an intptr_t. Since intptr_t is the same size as pointer on any platform that supports intptr_t, and seems to be generally meant for exactly this scenario, I'm not sure it's useful for GCC to warn when converting pointers/ints to/from intptr_t.

Thanks for responding!


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