-
March 26th, 2010, 01:14 AM
#1
Redefination problem
Hi,
I have a main.c file like this
Code:
#include "Headers.h"
extern char *myArray;
int main()
{
return 0;
}
the Headers.h file contains
char myArray[200];
When I compile this is giving error like redefination; different types of indirection
But my doubt is we can use pointers instead of arrays
please clarify me whether we can use extern with pointer or not
-
March 26th, 2010, 01:28 AM
#2
Re: Redefination problem
You probably should declare myArray as extern in the header:
Code:
extern char myArray[];
Then in main.c you define it:
-
March 26th, 2010, 02:31 AM
#3
Re: Redefination problem
Thanks for the quick response.
I changed the way you told.
It is working fine.
But my question is -- I can use pointer also in the main.c file
like char *myArray
But it is giving the compilation error -- like redefination; different types of indirection
-
March 26th, 2010, 02:37 AM
#4
-
March 26th, 2010, 09:01 AM
#5
Re: Redefination problem
Originally Posted by Rajesh1978
But my question is -- I can use pointer also in the main.c file
like char *myArray
But it is giving the compilation error -- like redefination; different types of indirection
I do not know what is your question, but a pointer is not an array, and an array is not a pointer.
-
March 26th, 2010, 09:11 AM
#6
Re: Redefination problem
To get a pointer to your array you could do something like :-
Code:
char* ptr = &myarray[0];
Be extremely careful using that pointer though, as by accessiing your array this way, the compiler has no idea of its bounds.
Get Microsoft Visual C++ Express here or CodeBlocks here.
Get STLFilt here to radically improve error messages when using the STL.
Get these two can't live without C++ libraries, BOOST here and Loki here.
Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
Always use [code] code tags [/code] to make code legible and preserve indentation.
Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.
-
March 27th, 2010, 01:17 PM
#7
Re: Redefination problem
It is not possible to declare variables of the same name twice.
You have already declared array 'myArray', if you want to declare a pointer to it, name it differently, e.g.
Code:
char *myArray_ptr = myArray;
Next time show the exact error message, line of code where the error is.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|