Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous behavior of variable declaration in c

i have the following code

#include<stdio.h>
int main()
{
    int a12345678901234567890123456789012345;
    int a123456789012345678901234567890123456;
    int sum;

    scanf("%d",&a12345678901234567890123456789012345);
    scanf("%d",&a123456789012345678901234567890123456);
    sum = a12345678901234567890123456789012345 + a123456789012345678901234567890123456;
    printf("%d\n",sum);

    return 0;
}

the problem is, we know that ANSI standard recognizes variables upto 31 characters...but, both variables are same upto 35 characters...but, still the program compiles without any error and warning and giving correct output...
but how?
shouldn't it give an error of redeclaration?

like image 972
MD. Khairul Basar Avatar asked Nov 02 '14 11:11

MD. Khairul Basar


1 Answers

Many compilers are built to exceed ANSI specification (for instance, in recognizing longer than 31 character variable names) as a protection to programmers. While it works in the compiler you're using, you can't count on it working in just any C compiler...

like image 193
Zeiss Ikon Avatar answered Oct 13 '22 12:10

Zeiss Ikon