What are "@" and "$" for C / C ++?

Until now, in MinGW, "$" seems to be just a basic character (like "a") that can be used in names (variables, functions, etc.). But this is not like one. Is there a hidden function to use '$' as part of the name that I am missing?

int $m = 2; printf("$m = %i", $m); 

Console output:

 $m = 2 

However, the “@” character creates an error when used as a character. error: stray '@' in program I assume that this means that he used something? Wikipedia and MSDN do not mention either character. And Google gives a lot of matches for "character" or "C".

+4
source share
1 answer

None of $ or @ is part of the standard C character set (C11 5.2.1 Character set , clause 3):

Both basic character sets of the initial and main versions should have the following elements: 26 capital letters of the Latin alphabet

  ABCDEFGHIJKLM NOPQRSTUVWXYZ 

26 lowercase latin letters

  ABCDEFGHIJKLM NOPQRSTUVWXYZ 

10 decimal digits

  0 1 2 3 4 5 6 7 8 9 

next 29 graphic characters

  ! " # % & ' ( ) * + , - . / : ; < = > ? [ \ ] ^ _ { | } ~ 

a space character and control characters representing the horizontal tab, vertical tab, and shape.

The C ++ standard says the same thing ( 2.2 character sets , clause 1):

The main source character set consists of 96 characters: a space character, control characters representing the horizontal tab, vertical tab, form feed and new line, as well as the following 91 graphic characters:

 abcdefghijklmnopqrstu vwxyz ABCDEFGHIJKLMNOPQRSTU VWXYZ 0 1 2 3 4 5 6 7 8 9 _ { } [ ] # ( ) < > % : ; . ? * + - / ^ & | ∼ ! = , \ " ' 

So, if you can or cannot use them (in general or even for a specific purpose), it depends on your implementation.

In your case, it looks like you are probably using GCC, which allows $ in identifiers as an extension, but does not allow @ - perhaps because GCC also compiles Objective-C code, where @ has special meaning.

From the GCC Documentation :

In GNU C, you can usually 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 several target computers, usually because the target assembler does not allow them.

+8
source

Source: https://habr.com/ru/post/1499449/


All Articles