Is _ (single underscore) a valid C++ variable name?

前端 未结 6 1795
挽巷
挽巷 2021-01-07 19:06

With gcc 4.7.2 this compiles just fine for me:

int main()
{
  int _ = 1;
  return 0;
}

Can I expect this to compile in general? I\'ve read

6条回答
  •  情歌与酒
    2021-01-07 20:01

    According to Stroustrup (3rd edition, section 4.9.3), an identifier consists of a sequence of letters and digits. The first character must be a letter. The underscore character is considered a letter.

    So, yes, it should be portable.

提交回复
热议问题