Why does a parameter have two "const" in its statement?

Asked

Viewed 135 times

4

I’m reading the tutorials on the website of lib Opencv and during reading I saw the declaration of a function with a variable in a format I’ve never seen. I wanted to know what it means, declare the variable in this way. Follow the function signature:

Mat& ScanImageAndReduceRandomAccess(Mat& I, const uchar * const table)

const uchar * const table I know it’s a pointer to a unsigned char, but I’ve never seen two const being used this way! This is my question: What is he trying to say?

  • 2

    I removed the Opencv tag because you could have found it in any library anywhere. The fact that the signature is like this is not something particular or specific to Opencv.

1 answer

4


const uchar * const table

I put in the Github for future reference.

Pointed objects are composed of two pieces of information, a pointer and the die itself. By default both are mutable.

The first const indicates that the stated content is constant and cannot be changed under normal conditions. But that alone doesn’t mean you can’t point to another completely different object.

The second const indicates that the pointer is also constant and cannot be changed.

So this function takes an argument that is "guaranteed" that will be read-only.

Guaranteed way of saying, there are ways to subvert it, though it shouldn’t.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.