-1

screenshot of my code and error data

This is my main.c file

#include "services_initialisations_prototype.h"
#include "services_functions_prototype.h"


void main(void)
    {
    initSfr();
    while(1){
        updateMatrix(404, 1);
        }
    return;
    }

this is my services_initialisations_prototype.h


#ifndef XC_HEADER_TEMPLATE_H
#define XC_HEADER_TEMPLATE_H

#include <xc.h> // include processor files - each processor file is guarded.  
#include <stdint.h>

//these are my function declarations
extern void initInterrupt();
extern void initIoc();
extern void initAdc();
extern void initTimer2();
extern void initSfr();


#ifdef  __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifdef  __cplusplus
}
#endif /* __cplusplus */

#endif  /* XC_HEADER_TEMPLATE_H */

this is my services_functions_prototype.h

#ifndef XC_HEADER_TEMPLATE_H
#define XC_HEADER_TEMPLATE_H

#include <xc.h> // include processor files - each processor file is guarded.  
#include <stdint.h>

//these are my function declarations
extern void updateMatrix(int, int);

#ifdef  __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifdef  __cplusplus
}
#endif /* __cplusplus */

#endif  /* XC_HEADER_TEMPLATE_H */

When I try to include two header files in MPLAB X IDE version 4.05, it seems like it is not identifying the second header file. i tried swapping the order, but still the second one is not detected.

The services_initialisation_prototype.h contains initialisations of SFRs and services_functions_prototype.h contains prototypes of other functions. these functions are independent of each other.

when i compile, it is showing that

function updateMatrix() is declared as implicit int. conflicting declarations for variable _updateMatrix()

which shows that the header file services_functions_prototype is not identified.

the screenshot attached shows the code in services_functions_prototype.h in grey color, and it seems that part of code is not executed.

When I copied the whole declarations from header file to my main file, it is working perfectly fine.

jauhar_k
  • 73
  • 2
  • 6
  • Please do not post links to images of error messages. Please edit your post and add your code as text into your post. Please post an [MCVE]. Please include error messages verbatim as text into your post. Please take your time and research [ask]. I also recommmend [question checklist](https://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist). What do you mean by "doesn't work"? What "does not work", in what way and how do you know that? Did you read the error messages? What research did you do and what did it resulted in? – KamilCuk Jul 25 '20 at 07:44
  • In the spirit of this forum - do you have a question to ask? what is your question? What mcu are you compiling for? (And you seem to be using free version of xc8 compiler - I advise to use sdcc instead, free xc8 always worked horrible. And if you are using pic18* for no particular reason, I advise to put them in the trash bin and move to stm32 or nrf instead). – KamilCuk Jul 25 '20 at 07:45
  • @KamilCuk I've edited the code. When i copied the whole declarations as extern to my main file, it is working fine. Also, i'm a student and using the free compiler is enough for my works. I'm using the pic16f1787. – jauhar_k Jul 25 '20 at 08:12

1 Answers1

1

You used the same include guard in both files. Because one file is included before the other, it defines XC_HEADER_TEMPLATE_H which makes #ifndef fail in the second file. Change them to something unique. Wiki include guard.

Remember that identifiers with two leading underscores or identifiers with a leading underscore and an upper case letter are reserved by C standard. Good documentation online is in gcc reserved names.

Use filename with uppercase like SERVICES_FUNCTIONS_PROTOTYPE_H_ and SERVICES_INITIALIZATIONS_PROTOTYPE_H_.

Notes:

  • Empty parameter list in function declaration declares a function that takes unknown count and type of parameters. Prefer explicitly writing void inside function parameter list to define a function that takes no argument, to enable compiler static checking. Ie. do void initInterrupt(void);. cppreference function declaration
  • Identifiers declared at file scope are implicitly with external linkage. Ie. externis just redundant., just void initSfr(void); instead of extern void initSfr(); cppreference storage-class
  • The extern "C" { part makes no sense in your headers - there is nothing inside it. It's typicall to put extern "C" { on top of the header file to include everything inside. If your headers would be used by a C++ compiler, the functions names would be mangled and not properly resolved. I believe I would suggest to just remove the extern "C" { part.
KamilCuk
  • 120,984
  • 8
  • 59
  • 111