2

I'm getting this odd error...

jos_log.c:16:13: error: field '_errno' declared as a function
    ERRNO    errno;
             ^

...when I compile this code:

typedef enum ERRNO_
{
   /* ... */
}
ERRNO;

typedef struct LOG_ENTRY_
{
   char *   message;
   ERRNO    errno;    // <--- Error here
   ERR_SEV  severity;
}
LOG_ENTRY;

Any ideas on what could be causing the problem?

0

1 Answer 1

2

The translation unit includes errno.h, through which errno is already defined as preprocessor macro, whose definition provokes the error.

In my case, with gcc (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1, the file:

#include <errno.h>
typedef int ERR_SEV;
typedef enum ERRNO_
{
   x
}
ERRNO;

typedef struct LOG_ENTRY_
{
   char *   message;
   ERRNO    errno;
   ERR_SEV  severity;
}
LOG_ENTRY;

yields the similar error:

a.c:12:13: error: field ‘__errno_location’ declared as a function
    ERRNO    errno;
             ^

as result of:

#   define errno (*__errno_location ())

within <bits/errno.h>, within <errno.h>. Without #include <errno.h>, no error.

Unless you have made a typo in posting the disgnostic, this would suggest that your <errno.h> imports the definition:

#define errno (*_errno ())

The solution is not to use errno as your field name.

Sign up to request clarification or add additional context in comments.

1 Comment

That was it! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.