Search code examples
cconstantsansi-c

Multiple const in one variable declaration


A colleague of mine is going a bit nuts with const in ANSI C and I wanted to know what you guys thought about it. He writes stuff like this for example:

const uint8* const pt_data

I understand where he's going with this but for me it makes the reading and maintainability harder with all these const everywhere.


Solution

  • It's a const pointer pointing to const data.

    • The first const prevents *pt_data = 10;
    • The second const prevents pt_data = stuff;

    It looks like it can be pretty legitimate.