Global structure doesn't work

667 views Asked by At

I am programming with Xmega and I need some flags used in more than one file. So I declared the flag as extern in the h-file and initialized it global in the main-file.

global.h:

#ifndef GLOBAL_H_
#define GLOBAL_H_

typedef struct GLOBAL_FLAGS {
    volatile uint8_t pidTimer:1;
    volatile uint8_t dummy:7;
}GLOBAL_FLAGS;

// declaration
extern GLOBAL_FLAGS gFlags;

#endif

main.c:

#include <avr/io.h>
#include <avr/interrupt.h>
#include "global.h"
#include "hv.h"
#include "pid.h"

// init
gFlags = {.pidTimer = 0, .dummy = 0};

// code....
int main(void){
// code....
// example use of flag
if(gFlags.pidTimer){
        hv_run_pid();
        gFlags.pidTimer = 0;
    }

I get some of Errors when im doing this.

Where I initilize it I get this:

Errors:

  • conflicting types for gFlags

  • field Name not in record or Union initializer

Warnings:

  • data Definition has no type or storage class

  • type Defaults to 'int' in declaration of 'gflags'

Where I want to use it i get this:

Error:

  • request for member 'pidTimer' in something not a structure or Union

I use Atmel Studio 7.

1

There are 1 answers

4
puzzled On BEST ANSWER

Thanks!

I switched

// init
gFlags = {.pidTimer = 0, .dummy = 0};

to

// init
GLOBAL_FLAGS gFlags;

and it works.