Results 1 to 5 of 5
#include<stdio.h>
int a;
int a=2;
int main()
{
printf("A %d\n",a);
return 0;
}
no error here
#include<stdio.h>
int a=3;
int a=2;
int main()
{
printf("A %d\n",a);
return 0;
}
Error ...
- 04-25-2008 #1
Redeclaration can any body explain
#include<stdio.h>
int a;
int a=2;
int main()
{
printf("A %d\n",a);
return 0;
}
no error here
#include<stdio.h>
int a=3;
int a=2;
int main()
{
printf("A %d\n",a);
return 0;
}
Error : Redeclaration of a
why it is not giving in first program why it is giving in second one
if include a file twice its including the file twice how to avoid such situations
thanks in adv
- 04-25-2008 #2
///////////////////////tt.h
int a=10
/////////////////////tt.c
#include<stdio.h>
#include"tt.h"
#include"tt.h"
int main()
{
return 0;
}
//////////////////////
$ gcc tt.c
error redeclarion of a
previous declaration of a was here
/////////////////////
how to avoid such kind of situations bcoz if am having hundreds of files and to take care such that its not included more than once is difficults is there any other technique to say compiler not to include one file more than once.....
some body help me regarding these two posts
thanks in advance
- 04-25-2008 #3Just Joined!
- Join Date
- Mar 2008
- Posts
- 23
int a=3;
int a=2;
surely this will give an error coz they are both initialized with same name and assigned
int a;
int a=2;
here u are just assigning a value to the first one, and it s globally defined , u can try to make it within ur main and u ll c the defference, redefinition error should occur if am not mistaken.
- 04-26-2008 #4
In your first program, "int a;" is a prototype: it is saying that in this program there exists some global int called a. It is just like a function prototype.
In the second, you are declaring two ints called a, which is illegal.
I hope this makes sense.
As far as avoiding the problem with including headers, you can do this by using a DEFINE protection.
This way, the preprocessor will only actually include the file once.Code:#ifndef TT_H_INCLUDED #define TT_H_INCLUDED int a = 10; #endif
DISTRO=Arch
Registered Linux User #388732
- 04-26-2008 #5


Reply With Quote