dimanche 24 mai 2020

Differences between `decltype(&normal_func)` and decltype`(normal_func)`

Given the declaration void close_file_func(std::FILE* fd){}, I found that decltype(&close_file_func) is the type of void (*)(_IO_FILE*) whereas decltype(close_file_func) is the type of void (_IO_FILE*)?

You could check the related code trough https://godbolt.org/z/QK5q3o.

For your convenience, i post the code and the execution output below.

#include<iostream>
#include<typeinfo>

void close_file_func(std::FILE* fd);

int main()
{
    std::cout << typeid(close_file_func).name() << std::endl;
    std::cout << typeid(&close_file_func).name() << std::endl;
}

//Terminate outputs:
//FvP8_IO_FILEE
//PFvP8_IO_FILEE

And echo 'PFvP8_IO_FILEE' | c++filt -t says void (*)(_IO_FILE*) ,

echo "FvP8_IO_FILEE" | c++filt -t says void (_IO_FILE*).

I thought over and over, but i still could not understand. I would be grateful for any hint on this question.

Aucun commentaire:

Enregistrer un commentaire