How do I find variables that should be constants in C?

Viewed 112

So, I've got this code:

uint8_t* pbytes = pkt->iov[0].iov_base;

that creates a pointer to the start of an ethernet packet in a structure.

And I ask my friend to look at the code, and he says: "You're not modifying that, and it would be really confusing if you did, so make it const".

And this seems like a good idea, so:

const uint8_t* pbytes = pkt->iov[0].iov_base;

or even:

const uint8_t * const pbytes = pkt->iov[0].iov_base;

And now I am thinking, I bet there are loads of other places where I could have done that, and I bet the compiler is going to be better at finding them than me.

Any ideas how I ask it the question? (gcc preferred, but no problems using a different compiler or a linting tool as long as they will run on unix).

2 Answers
Related