c declaring variables in blocks

Posted by anon on Stack Overflow See other posts from Stack Overflow or by anon
Published on 2010-04-16T22:51:03Z Indexed on 2010/04/16 23:03 UTC
Read the original article Hit count: 378

Filed under:
|
|

I know that in C++, I can declare variables pretty much everywhere.

I recall once reading that in C, variables must be declared at the top of a function i.e. the following is invalid:

void foo() {
  int good;
  if (...) {
    int bad;
  }
}

In the above code, is the declaraing of the bad varaible legal by C standards, or only legal due to a gcc extension?

Thanks!

© Stack Overflow or respective owner

Related posts about c

    Related posts about declare