Search code examples
c++pointersvariablesfunction-pointersdeclaration

unknown construct/variable declaration in c++


I am fairly new to c++. I have some experience with programming in general and in C in particular though. I have a c++ project written by someone else which I am trying to comprehend at the moment, and it includes several variable declarations in this format:

 uint64_t(*const col_timestamp)(const uint8_t* col_buf);

I fail to wrap my head around what this means. Is it even a variable declaration? I would understand the two seperate declarations of the constant pointer col_timestamp pointing to a variable of type uint64_t and the pointer col_buf to a variable of type const uint8_t like this:

uint64_t * const col_timestamp;
const uint8_t * col_buf;

But I don't think that is what it means since I dont see a reason to write it in this way then. Help would be very appreciated since I am kind of stuck here.

I am sorry if this is a duplicate question of sorts, but I simply don't know what to search for, and I guess this is very simple to answer for someone knowledgeable in c++.

Thanks in advance!


Solution

  • This

    uint64_t(*const col_timestamp)(const uint8_t* col_buf);
    

    is a declaration of a constant pointer to function that has the return type uint64_t and one parameter of the type const uint8_t *.

    For example if you have a function declared like

    uint64_t func_col_timestamp( const uint8_t *col_buf );
    

    You could declare and initialize a pointer to the function like

    uint64_t(*const col_timestamp)(const uint8_t* col_buf) = func_col_timestamp;