Hello,

I have a quick question about c/c++ syntax. Basically I am wondering when it is allowable to have numbers in identifiers. My compiler happens to allow numbers in:

  • Function names
  • Class names
  • Variable names
  • Pre-processor names

As long as they do not begin with numbers. Is this standard functionality? I just ask because it feels weird to have a function called euler2 (for calculating eulerian numbers of the second kind). Is there any reason I should rename it to eulerTwo?

I checked the ISO C specification and it seems to suggest that it should be okay for all identifiers, but then it is rather vague about what identifiers are, exactly.

For now I am assuming that this is okay, I just wanted to double check and could not find anything else about this online.

Thanks.

Is there any reason I should rename it to eulerTwo?

You can, but it's not necessary. There is nothing wrong with using numbers in function names -- it's actually pretty commen.

As long as they do not begin with numbers. Is this standard functionality?

Yes.

but then it is rather vague about what identifiers are, exactly.

You might be reading the wrong section. Section 2.11 (C++ n3242) gives both a grammar and a detailed description of syntax. Section 6.4.2 (C99) is equally detailed.

Thank you very much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.