0
votes

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. - Some programmer dude

1 Answers

4
votes

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