1

When i compile and run the following code, codeblocks(windows 7 64-bit) issues a couple of warnings:-

#include<stdio.h>
#include<stdlib.h>
extern int i=10;     //Warning

int main()
   {
       extern int i;
       printf("%d\n",i);
   }

int i;

The warnings are as follows:-

Line 3: warning: 'i' initialized and declared 'extern' [enabled by default]

Any explanation for this warning?

yulian
  • 1,601
  • 3
  • 21
  • 49
chanzerre
  • 2,409
  • 5
  • 20
  • 28

2 Answers2

3

Taken the help from here

Thats a valid syntax. The problem is that extern keyword is redundant because the object is initialised in the same compilation unit.

Community
  • 1
  • 1
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
1

That's normal, « extern i ; » means « Okay, there is a variable i somewhere in another file (already initialized). », and you try to affect to it a new value!

I think you should have a look at the « extern » key word.

Holt
  • 36,600
  • 7
  • 92
  • 139