I was doing some system programming in C++, and I want to pass the errno variable in linux systems to my exception handler. You can see example code in here https://pastebin.com/ppgMc8Hj
#include <sys/stat.h>
#include <cerrno>
#include <iostream>
#include <cstring>
std::string errorString(int errno){
return std::strerror(errno);
}
int main(){
struct stat sb;
errno = 0;
if(stat("/jdfj/", &sb)){
errorString(errno);
}
else{
std::cout << std::boolalpha << S_ISDIR(sb.st_mode) << std::endl;
}
}
But it returns an error like this
In function 'int main()':
14:26: error: invalid conversion from 'int' to 'int* (*)()' [-fpermissive]
6:13: note: initializing argument 1 of 'std::string errorString(int* (*)())'.
I have seen here http://en.cppreference.com/w/cpp/string/byte/strerror that the standard function that returns a string from errno accepts an int as argument. My question is
- If it is an int type why doesn't it work in the above code?
- If not what is it's type?