Why when the ON
or OFF
mode of strict compliance with ANSI C
program produces different results? Compliance with strict about writing of the reasons that most modern industrial compilers default to some expansion of its own language, and some by default is C99, etc.
#include <stdio.h>
#include <string.h>
int main (void)
{
int len;
len = strlen ("??=");
printf ("len=%d\n", len);
return 0;
}
Here is the result. In both cases submitted compiler option -w
to suppress warnings:
$ gcc t.c -w
$ ./a.out
len=3
$ gcc t.c -ansi -w
$ ./a.out
len=1
When it is not in ansi mode gcc
is not converting the trigrpah ??=
(length 3) to #
(length 1) which explains the length difference.
If you had not suppressed warnings gcc
would warn that it is ignoring the trigraph in the non ansi mode(see it live):
warning: trigraph ??= ignored, use -trigraphs to enable [-Wtrigraphs]
You can read more about dialect options in the Options Controlling C Dialect section of the gcc
docs. It says the following for -ansi
:
[...] It also enables the undesirable and rarely used ISO trigraph feature. [...]
Trigraphs are covered in the draft C99 standard section 5.2.1.1
Trigraph sequences which says:
Before any other processing takes place, each occurrence of one of the following sequences of three characters (called trigraph sequences12)) is replaced with the corresponding single character.
and the following sequences include:
??= #