Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stderr undeclared identifier

Tags:

c

void
argmatch_valid (const char *const *arglist,
            const char *vallist, size_t valsize)
{
  size_t i;
  const char *last_val = NULL;

  fprintf (stderr, _("Valid arguments are:"));
  for (i = 0; arglist[i]; i++)
    if ((i == 0)|| memcmp (last_val, vallist + valsize * i, valsize))
    {
      fprintf (stderr, "\n  - `%s'", arglist[i]);
      last_val = vallist + valsize * i;
    }
    else
    {
      fprintf (stderr, ", `%s'", arglist[i]);
    }
  putc ('\n', stderr);
}

I am getting the following although I have included stdio.h in my .c file

warning C4013: 'fprintf' undefined; assuming extern returning int

error C2065: 'stderr' : undeclared identifier

warning C4013: 'putc' undefined; assuming extern returning int

I thought of disabling the warning by #pragma warning( disable :4013 ) but wanted to compile the code clean.

Thanks in advance

like image 395
Capricorn Avatar asked Mar 08 '13 08:03

Capricorn


1 Answers

While stdio.h should work, sometimes you need to include stdlib.h as well. Include the following:

#include <stdio.h>
#include <stdlib.h>

Declare both of these includes at the TOP of the same .C file your argmatch_valid function above is defined.

My crystal ball suggests that the stdio.h you think you are including is getting wrapped by a comment or within another preprocessor section that is getting wiped out. Maybe you can post your entire source file. Someone will likely spot the real error.

like image 164
selbie Avatar answered Nov 03 '22 16:11

selbie