I am looking at the following code in an SO "Low Quality" post to make sure the sample works, and my question is why can't I print errno's value?
errno = 0;
if(fp == NULL && errno == ENOENT)
perror("file not exist");
(gdb) p errno
Cannot find thread-local variables on this target
In my Ubuntu installation, I have the following section in
/* Function to get address of global `errno' variable. */ extern int *__errno_location (void) __THROW __attribute__ ((__const__)); # if !defined _LIBC || defined _LIBC_REENTRANT /* When using threads, errno is a per-thread value. */ # define errno (*__errno_location ()) # endif
errno is not necessarily a variable. For various reasons you may want to have a function returning the error value for you rather than a simple
extern int.1 That is why you can't print its value using GDB.
1 of course, as you can see the function call should return the pointer to the actual variable and the
errno macro would dereference it.