Unknown type name for structure

Go To Last Post
24 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello - I'm beating my head against this piece of the wall, I'm using AS7 and it gives an error "unknown type name 'OutState' and points the cursor at the OutState argument of my DetermineState function.  Any ideas of why are welcome! thanks, paul

void ADC_setup();
void Timer_Setup();
float ReadADC(uint8_t, uint8_t);
void CalAnalog();
float Voltages[3];
float ReadVoltages(float Voltages[]);
struct OutState{
	uint8_t OutputCompare;
	int LED_Green;
	int LED_Yellow;
	int LED_Red;
};

struct OutState OutputState;
typedef enum {SHORTED, OPEN, CALIBRATION, BULK, ACCEPT, FLOAT, FAULT} Mode;
enum Mode CurrentMode;
DetermineState(Mode CurrentMode, float Voltages, OutState OutputState);

 

Last Edited: Sat. Mar 25, 2017 - 09:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You need to put typedef before struct or the compiler won't recognize it as a type.

"Some people die at 25 and aren't buried until 75." -Benjamin Franklin

 

What is life's greatest illusion?"  "Innocence, my brother." -Skyrim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

paulofelora wrote:
it gives an error "unknown type name 'OutState' and points the cursor at the OutState argument of my DetermineState function.

Because you don't have a type OutState, but a struct OutState. Either make it a type by using typedef, or put a "struct" in front of it as 3 lines before with OutputState.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Moving to general programming forum.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The type is

struct OutState

and not just OutState.

 

So in the function, it must be:

 

DetermineState(Mode CurrentMode, float Voltages, struct OutState OutputState);

 

edit: this is the same answer as #3, but I like to make things absolutely clear.

Last Edited: Sun. Mar 26, 2017 - 12:24 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And that shows why it's "cleaner" to typedef ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Btw, correct me if I'm wrong, but if using typedef to define an OutState type, it would be:

typedef struct {
	uint8_t OutputCompare;
	int LED_Green;
	int LED_Yellow;
	int LED_Red;
} OutState;

and not

typedef struct OutState{
	uint8_t OutputCompare;
	int LED_Green;
	int LED_Yellow;
	int LED_Red;
} ;

right?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Clawson's fix solved my problem - thanks! Now I have another - "Storage size of CurrentMode isn't known" - the error cursor points to CurrentMode:

 

typedef enum {SHORTED, OPEN, CALIBRATION, BULK, ACCEPT, FLOAT, FAULT} Mode;
enum Mode CurrentMode;

Seems like it *ought* to be known - 7 items in a list indecision

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You've defined the type - no need to repeat enum.
Mode CurrentMode;

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

El Tangas wrote:
Btw, correct me if I'm wrong

In fact you can do both...

typedef struct OutState_tag_name {
	uint8_t OutputCompare;
	int LED_Green;
	int LED_Yellow;
	int LED_Red;
} OutState_type_name;

You can later create variables as either:

struct OutState_tag_name one_of_these;

or

OutState_type_name or_one_of_these;

However using "tags" is more cumbersome so in the coding standard I have adhered to in the past the only time tags are ever used are in self-referential structures (as often in linked lists):

typedef struct data_tag {
    struct data_tag * prev;
    struct data_tag * next;
    int n;
    long l;
    char c;
} data_t;

Later one instantiates as data_t but the "struct data_tag *" has allowed for self-referential pointers to be defined.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

El Tangas wrote:
So in the function, it must be:

 

DetermineState(Mode CurrentMode, float Voltages, struct OutState OutputState);

Although, on a small microcontroller like an AVR, you should probably pass a pointer to the structure - rather than copy the entire structure ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not just micros! 

 

I was looking at something the other day that inadvertently involved shuffling several MB about. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well I've taken several pieces of advice, and now have:

typedef struct OutState{
	uint8_t OutputCompare;
	int LED_Green;
	int LED_Yellow;
	int LED_Red;
};

struct OutState OutputState;
typedef enum {SHORTED, OPEN, CALIBRATION, BULK, ACCEPT, FLOAT, FAULT} Mode;
Mode CurrentMode;
void DetermineState(Mode CurrentMode, float Voltages, struct OutState *OutputState);

However, now I get "Conflicting types for 'CurrentMode'" (error cursor pointing to "Mode CurrentMode") and "Conflicting types for 'DetermineState'"  (error cursor pointing to  function declaration).  Still lost!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Conflicting types" means that you have two (or more) declarations of an item with differing types - so the code you posted is not the complete picture

 

If you look in the raw build output, you should see additional information telling you where, exactly, the two declarations are.

 

The code you posted shows only the function prototype - not its actual definition. Have you, perhaps, changed one without also updating the other ... ?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I haven't actually written the function, I've only yet declared it.  I did a 'Find' across the entire project, and that's the only instance.  Odd.  I wonder if AS7 is confused about "previous files"?  Should I post the entire output?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you took the advice why do you persist in using tags? 

 

Also why is CurrentMode both a global and a function parameter? One will hide the other. If it's being used to pass the same thing why is it global? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK I *think* I've taken clawson's advice & removed tags.  I stopped declaring CurrentMode twice.

void usart_init(uint16_t ubrr);
char usart_getchar( void );
void usart_putchar( char data );
void usart_pstr(char *s);
void ADC_setup();
void Timer_Setup();
float ReadADC(uint8_t, uint8_t);
void CalAnalog();
float Voltages[3];
float ReadVoltages(float Voltages[]);
typedef struct {
	uint8_t OutputCompare;
	int LED_Green;
	int LED_Yellow;
	int LED_Red;
} OutState;

typedef enum {SHORTED, OPEN, CALIBRATION, BULK, ACCEPT, FLOAT, FAULT} Mode;

void DetermineOutputState(Mode SomeMode, float SomeFloats, struct OutState *SomeState);

In my main.c I declare & initialize some of the variables:

int main( void ) {
	Mode CurrentMode;
	OutState OutputState;
	CurrentMode = FAULT;
	OutputState.OutputCompare = 16;
	OutputState.LED_Green = 0;
	OutputState.LED_Yellow = 0;
	OutputState.LED_Red = 0;

But I'm getting errors like

 

C:\Users\paul\Documents\Atmel Studio\7.0\Nano_BatteryTender_0\Nano_BatteryTender_0\Includes.h(20,3): error: conflicting types for 'OutState'
         } OutState;
           ^

And

 

C:\Users\paul\Documents\Atmel Studio\7.0\Nano_BatteryTender_0\Nano_BatteryTender_0\Includes.h(22,15): error: redeclaration of enumerator 'SHORTED'
         typedef enum {SHORTED, OPEN, CALIBRATION, BULK, ACCEPT, FLOAT, FAULT} Mode;
                                ^

I get an error for each of the enum names...  still lost indecision

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You're defining OutState with a typedef. As clawson said, the whole point of that is that you then do not need to put struct with it when you use it!

 

In fact, you must not use struct with it.

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ahhh finally GOT IT, so I removed 'struct' from the function prototype.  I've still got lots of errors... Conflicting type for DetermineOutputState, for Mode, and for OutState.

 

Thank y'all for bearing with my mental density...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Again, go to the Build OUtput window for further details of where the conflict arises ... 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Looking at the Output, I see:

 

C:\Users\paul\Documents\Atmel Studio\7.0\Nano_BatteryTender_0\Nano_BatteryTender_0\Includes.h(20,3): error: conflicting types for 'OutState'
         } OutState;
           ^
        In file included from .././main.c:19:0:
C:\Users\paul\Documents\Atmel Studio\7.0\Nano_BatteryTender_0\Nano_BatteryTender_0\Includes.h(20,3): info: previous declaration of 'OutState' was here
         } OutState;
           ^

I do use OutState in main.c, where I declare a variable "OutState OutputState;" but that shouldn't cause a conflict, wouldn't think... still lost

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So that is telling you that you are declaring OutState at main.c line 19 and also in includes.h at line 20.

 

Use one or the other, not both. 

 

If the type is only used in main.c perhaps keep the definition there but if it's to used in multiple files (that all include the file includes.h) then define it in the header. 

 

BTW a header called includes.h conveys almost exactly nothing about what it contains from that name! 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good point, clawson, will fold my Includes.h into main.c, it really doesn;t serve any good purpose as a separate file

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ahhh the sweet smell of successful compilation!  Thanks you all for your kind & patient help! paul