0

I'm trying to solve but I don't know where a mistake.

int main() {
    for (int i = 0; i < 3; i++) {
        pid_t pid = fork();
  }
    return 0;
}
1
  • Tell GCC to use the C99 standard (or later). Read the GCC online documentation for your version of GCC for the flags to use. Commented Oct 28, 2016 at 11:02

1 Answer 1

4

You're declaring your i variable inside the for loop. This is common in C++, but was added (surprisingly recently) in the C99 specification.

Move the declaration of your i variable outside of the for loop:

int main() {
    int i;
    for (i = 0; i < 3; i++) {
        pid_t pid = fork();
  }
    return 0;
}

Alternatively, you can tell GCC to compile your code in C99 mode:

gcc -std=c99

Or if you want to retain GCC-specific features, use:

gcc -std=gnu99
Sign up to request clarification or add additional context in comments.

5 Comments

1999 is recent for you ?)
Best would just be to pass to a more recent version of gcc which has even C11 as a default.
@JensGustedt Considering Visual Studio 2013 only implemented some of C99 features, I'd say C99 support is a recent event (not the spec being recent).
you said " (not the spec being recent) ". is " spec " an abbreviation for " specification " ? @Jonathon Reinhart
@FadyHany Yes, "spec" is a clipping of "specification". When I said "surprisingly recently in the C99 specification" I meant that compiler support for C99 is fairly recent, even though the spec(ification) is much older.

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.