I would answer for the C language. Note that there isn't any such thing as C/C++. Both are separate languages and C is not a subset of C++.
Beside those possibilities, that you described, @
can be also placed in header names, but it's not a common practice:
main.c:
#include <stdio.h>
#include "fancy@header.h"
int main(void)
{
foo();
return 0;
}
fancy@header.h:
static void foo(void)
{
printf("whatever\n");
}
For a Standard reference to cover this, you might look into C11 §5.2.1/p3 that covers the basic execution character set, which does not include the @
character. This paragraph also provides a list of cases that may allow a @
character (emphasis mine):
In the basic execution character set, there shall be control
characters representing alert, backspace, carriage return, and new
line. If any other characters are encountered in a source file (except
in an identifier, a character constant, a string literal, a header
name, a comment, or a preprocessing token that is never converted to a
token), the behavior is undefined.
In case of identifiers, see C11 §6.4.2.1/p3:
Each universal character name in an identifier shall designate a
character whose encoding in ISO/IEC 10646 falls into one of the ranges
specified in D.1.71) The initial character shall not be a universal
character name designating a character whose encoding falls into one
of the ranges specified in D.2. An implementation may allow multibyte
characters that are not part of the basic source character set to
appear in identifiers; which characters and their correspondence to
universal character names is implementation-defined.
The D.1 (normative) appendix section lists ranges of allowed characters. As you might check the @
character can be represented as U+0040
in UCS, that is outside of allowed range:
00A8, 00AA, 00AD, 00AF, 00B2−00B5, 00B7−00BA, 00BC−00BE, 00C0−00D6,
00D8−00F6, 00F8−00FF (...)
Even with that, compiler might allow @
character as language extension. C11 J.5.2/p1 Specialized identifiers (Common extensions) contains:
Characters other than the underscore _, letters, and digits, that are
not part of the basic source character set (such as the dollar sign $,
or characters in national character sets) may appear in an identifier
(6.4.2).
For instance GCC allows $
sign as GNU extension in that way:
In GNU C, you may normally use dollar signs in identifier names. This
is because many traditional C implementations allow such identifiers.
However, dollar signs in identifiers are not supported on a few target
machines, typically because the target assembler does not allow them.