variable name confusion

void tst()
{
  { char  x; _x = 0; } // ... error C202: '_x': undefined identifier
  { char _x;  x = 0; } // No errors! Are "_x" and "x" the same here?
}

Parents
  • The first error is expected; _x isn't visible by the time it's referenced.

    For the second error, it seems more likely that C51 doesn't correctly remove 'x' when it goes out of scope. It might also be an odd consequence of the C89 definition. I'd have to do some standards-lawyering to see exactly what changed with local blocks between C89, C++, and C99. Note that Keil doesn't claim to be C99 compliant anyway.

    Identifiers that begin with an underscore are reserved for the language or implementation and shouldn't be used. (Yes, I know some people like to do this in libraries, and they even get away with it. The standard libraries are one reason that range of identifiers is reserved. That doesn't mean everyone else should do it, too.)

Reply
  • The first error is expected; _x isn't visible by the time it's referenced.

    For the second error, it seems more likely that C51 doesn't correctly remove 'x' when it goes out of scope. It might also be an odd consequence of the C89 definition. I'd have to do some standards-lawyering to see exactly what changed with local blocks between C89, C++, and C99. Note that Keil doesn't claim to be C99 compliant anyway.

    Identifiers that begin with an underscore are reserved for the language or implementation and shouldn't be used. (Yes, I know some people like to do this in libraries, and they even get away with it. The standard libraries are one reason that range of identifiers is reserved. That doesn't mean everyone else should do it, too.)

Children
More questions in this forum