Operating System - HP-UX
1745782 Members
3524 Online
108722 Solutions
New Discussion

undeclared constants when compiling with gcc -std=c99

 
SOLVED
Go to solution
maxime2
Occasional Contributor

undeclared constants when compiling with gcc -std=c99

Hello,

I use gcc to compile on HP-UX ia V2. When I use '-std=c99', the compiler returns many undeclared constants errors (i.e. EILSEQ, EINVAL, E2BIG, etc.). If I remove this c99 option, then the program compiles fine.

Here is a simple example to reproduce the issue:

 

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

int main() {
    if (EINVAL == 22) {
        printf("Invalid argument\n");
    } else {
        printf("unknown EINVAL\n");
    }
    return 0;
}

Works fine if I compile this program without '-std=c99'.

$ gcc test.c -o test
$ ./test
Invalid argument

Now if I compile it with -std=c99:

$ gcc -std=c99 test.c -o test:
test.c: In function 'main':
test.c:6: error: 'EINVAL' undeclared (first use in this function)
test.c:6: error: (Each undeclared identifier is reported only once
test.c:6: error: for each function it appears in.)

Any idea why I get such error with c99?

Thank you in advance for your help.

Maxime

2 REPLIES 2
Steven Schweda
Honored Contributor
Solution

Re: undeclared constants when compiling with gcc -std=c99

> I use gcc to compile on HP-UX ia V2.

   Actual output from, say:
       uname -a
       gcc -v
would be more helpful than your vague descriptions.  Around here:

dyi# uname -a
HP-UX dyi B.11.31 U ia64 4235313755 unlimited-user license

dyi# gcc -v
Using built-in specs.
Target: ia64-hp-hpux11.31
Configured with: ../gcc-4.3.3/configure
Thread model: posix
gcc version 4.3.3 (GCC)

   I know approximately nothing about c99 or what "-std=c99" does to
GCC, but a quick look at /usr/include/sys/errno.h (pulled in by
/usr/include/errno.h) suggests that defining _INCLUDE_POSIX_SOURCE might
be useful:

dyi# gcc -o test_c99 test_c99.c
dyi#
dyi# gcc -o test_c99_c99 -std=c99 test_c99.c
test_c99.c: In function 'main':
test_c99.c:6: error: 'EINVAL' undeclared (first use in this function)
test_c99.c:6: error: (Each undeclared identifier is reported only once
test_c99.c:6: error: for each function it appears in.)
dyi#
dyi# gcc -o test_c99_c99 -std=c99 test_c99.c -D_INCLUDE_POSIX_SOURCE
dyi#

   If you have some good reason to specify "-std=c99", then it might
pay first to learn what it does.

maxime2
Occasional Contributor

Re: undeclared constants when compiling with gcc -std=c99

Thank you.

This indeed works for the constants inside errno.h. However, when I compiled my program I still got other undefined constants and functions (like CODESET, snprintf, etc.)

I found out that using the standard 'gnu99' solves all these issues.

From the man page of gcc:

gnu99 is ISO C99 plus GNU extensions.