Tags: /
c
/
As mentioned in C standards (see here, for a draft version of C99, under section 6.4.2), a valid C identifier
… is a sequence of non-digit characters (including the underscore
_
,the lowercase and uppercase Latin letters, and other characters) and digits …
That means a $
sign cannot appear anywhere in an identifier.
Yet some compilers allow variable names having $
via extensions.
(So yeah, this is not standard C and therefore is not portable.)
Consider the following program:
#include<stdio.h>
int fn$a$()
{"\nExecuted!");
printf(
}
int main()
{int $id=3;
"\n%d", $id);
printf(
fn$a$();return 0;
}
It has two identifiers with '$' in them:
$id
fn$a$
.But will still compile without errors in both gcc (6.3.0) and clang (4.0.1) using default flag values.
And print
3
Executed!
upon execution.
Interesting isn't it? :-)