Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Any help is greatly appreciated.
I have four files pasted below. when I try to compile with this command:
gcc -o test Test.c main.c

Got these errors:
In file included from Test.h:4,
from Test.c:1:
Types.h:9:7: warning: no newline at end of file
Test.c:9: error: syntax error before "Status"
In file included from Test.h:4,
from main.c:1:
Types.h:9:7: warning: no newline at end of file
main.c: In function `main':
main.c:6: error: `Status_Ptr_In_Header' undeclared (first use in this function)
main.c:6: error: (Each undeclared identifier is reported only once
main.c:6: error: for each function it appears in.)

main.c:
C
#include "Test.h"

int main(void)
{
	Status * Status_Ptr;
	Status_Ptr = (Status *) Status_Ptr_In_Header;

	int xx = (int)(&Status_Ptr->Status_1);

	printf("Status_Ptr->Status: %d", xx);
	printf("This is main.");

	return 1;
}

Test.h:
C
#ifndef TEST_H
#define TEST_H
#include "Types.h"

typedef struct STATUS_STRUCT {
	Status_Enum Status_1;
	Status_Enum Status_2;
	Status_Enum Status_3;
}Status;

extern Status * Status_Ptr_In_Test;

#endif

Test.c:
C
#include "Test.h"

Status MyStatus = {
	STATUS_ONE,
	STATUS_ONE,
	STATUS_ZERO
};

(Status *)Status_Ptr_In_Test = &MyStatus;

C
Types.h:

#ifndef TYPES_H
#define TYPES_H

typedef enum STATUS_ENUM{
	STATUS_ZERO = 0,
	STATUS_ONE = 1
}Status_Enum;

#endif
Posted
Updated 27-Aug-12 3:34am
v3
Comments
[no name] 27-Aug-12 9:36am    
The title of your question and the contents have nothing to do with each other.
Tikot123 27-Aug-12 10:27am    
One of the error is
main.c:6: error: `Status_Ptr_In_Header' undeclared (first use in this function).
I thought using the term "extern" should make the pointer global. Hence the title.
Tikot123 27-Aug-12 10:37am    
All the errors in main.c are resolved. In function `main' I changed:
`Status_Ptr_In_Header' to 'Status_Ptr_In_Test'.

1 solution

The code in test.c is a bit crappy.
Solve one error after the other.

What it boils down to is this :

CSS
Status MyStatus = {
STATUS_ONE,
STATUS_ONE,
STATUS_ZERO
};


What are you trying to do here ? Create an an array or enum ?
My guess is here is that it is suppused to be an array right ?
Then it should be :
Status Mystatus[] = {STATUS_ONE, STATUS_ONE, STATUS_ZERO};
this is also fine :
Status Mystatus[3] = {STATUS_ONE, STATUS_ONE, STATUS_ZERO};
But actually the first method is better, because if you add an element you don't have to change the 3 into a 4, the compiler finds out how many elements are in the array

I actually see a lot more errors because for instance in main.c you do
Status_Ptr = (Status *) Status_Ptr_In_Header;
and Status_Ptr_In_Header is never declared. What you need here is this to change it into Status_Ptr_In_Test;
 
Share this answer
 
v2
Comments
Tikot123 27-Aug-12 9:42am    
I wanted to initialize the struct "Status" which is a typedef of STATUS_STRUCT .
Philip Stuyck 27-Aug-12 9:45am    
Status is a type and cannot be initialised, only variables are initialised. You are trying to initialise myStatus.
Tikot123 27-Aug-12 10:27am    
Sorry... your correct. My bad.
Tikot123 27-Aug-12 10:35am    
All the errors in main.c are resolved. In function `main' I changed:
`Status_Ptr_In_Header' to 'Status_Ptr_In_Test'.
Philip Stuyck 27-Aug-12 10:48am    
If it works please mark me as solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900