Shreyas S
Shreyas S

Reputation: 358

Use of GCC's -Wpointer-arith

GCC documentation says

-Wpointer-arith Warn about anything that depends on the "size of" a function type or of 'void'. GNU C assigns these types a size of 1, for convenience in calculations with 'void *' pointers and pointers to functions. In C++, warn also when an arithmetic operation involves' NULL'.

But I cannot think of a usecase where this can be useful instead of creating nuisance. Any examples?

Upvotes: 8

Views: 3693

Answers (1)

clarkcox3
clarkcox3

Reputation: 589

All of those operations are undefined according to the C standard. This warning is useful for pointing out situations where the code may work under GCC, but will fail with other compilers.

Upvotes: 3

Related Questions