So I have a list of clockings in my udata in, let's say, clock.c. I have read that udata has to be accessed through a pointer, well okay, fair enough.

Above defines.h

//Warning! This has to be conform the linkerscript, you can not just increase it.
#define KEYLENGTH 6

//A clocking consists out of a key, time and in/out (and status)
//All the clockings together are the "clockings" list.
//These clockings will await to be transmitted.
typedef struct
    unsigned isActive:1;
    unsigned needsTransmit:1;
    unsigned inOut:1;
    unsigned val1:1;
    unsigned val2:1;
    unsigned val3:1;
    unsigned val4:1;
    unsigned val5:1;
} byte;

typedef struct
    byte bits;
    unsigned char key[KEYLENGTH];
    unsigned char time[6];
} Clocking;

Above clock.c file.

#include "defines.h"
#pragma udata large_udata
Clocking clocking_queue[CLOCKINGLISTLENGTH];
#pragma udata
Clocking *clockings = clocking_queue;//Access udata through pointer!

In eeprom.c file.

#include "defines.h"
extern Clocking *clockings;

void writeClockingToEEPROM(char clockingIndex){
 int eepromIndex = 0;

So my question is: "How to access udata from another file through a pointer". I simply want to use my clockings_queue (which should be accessed through *clockings pointer) in my EEPROM.c, so that I can store clockings in EEPROM.


1 Answer 1


The compiler doesn't know where clockings is in eeprom.c. There's nothing to tell the compiler that clockings is in clock.c.

In order to fix this, move extern Clocking *clocking; from eeprom.c into defines.h. This way, clock.c and eeprom.c know that clockings exists. The declaration of clockings should be in the header. The definition should be in clock.c (as it currently is).

Here's a link for an explanation on extern: http://www.geeksforgeeks.org/understanding-extern-keyword-in-c/

  • \$\begingroup\$ Both include defines.h. Is it safe to forward-declare Clocking *clocking as an extern variable? Even when I declare it later on as a regular variable (in clock.c)? \$\endgroup\$
    – aaa
    Commented May 4, 2015 at 14:52
  • \$\begingroup\$ @FauZe Make sure the contents of the header are wrapped with an #ifndef [Some Name] #define [Some Name] #endif. Or place a #pragma once statement at the top of the file. This will tell the compiler to use the file only once during compilation. I think the Microchip compilers support #pragma once. In order to use clockings in multiple c files, it needs to be forward declared in a header file. That way, the compiler knows about the variable. \$\endgroup\$
    – CurtisHx
    Commented May 4, 2015 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.