Problems with macros and preprocessor
Posted: Thu Oct 01, 2020 1:38 pm
Hi,
I'm having problems with the usage of macros. I've a C stack provided by a company and I'm trying to porting it on XMOS. This stack is composed of several folders that I copied in the "src" folder of my project. I also added in the Properties of my project the paths to include the stack files.
The main problems are these:
1) in a .h file it is defined this:
And in another .h file (in the same folder) they wrote:
In the second file, it doesn't see the definition of MY_HEADER (that 3 lines are grey), but in the first file I see that MY_HEADER is defined. What's happening?
I think that macros are, let's call it, global because is something done before compiling. So I think that in any file I could use them.
What am I missing?
2) The stack has a part of the code to check if the platform in use has implemented standard C definitions.
In particular, it checks for the definition of _STDDEF_H, which is defined in "stddef.h". This macro doesn't seem defined either.
So I suppose there is something I'm missing in project paths or something similar.
Does anyone know what's happening?
Have I to organize the project structure in a different way?
Let me know if you need more details to understand the problem.
Ah another thing. I've alrady did the porting of this stack on another platform based on a 32-bit microcontroller. And I didn't have this kind of problems, so I suppose it's a problem with XMOS preprocessor or some proprerties I'm not configuring correctly.
I'm having problems with the usage of macros. I've a C stack provided by a company and I'm trying to porting it on XMOS. This stack is composed of several folders that I copied in the "src" folder of my project. I also added in the Properties of my project the paths to include the stack files.
The main problems are these:
1) in a .h file it is defined this:
Code: Select all
#ifndef MY_HEADER
#define MY_HEADER "my_header.h"
#endif
Code: Select all
#ifdef MY_HEADER
#include MY_HEADER
#endif
I think that macros are, let's call it, global because is something done before compiling. So I think that in any file I could use them.
What am I missing?
2) The stack has a part of the code to check if the platform in use has implemented standard C definitions.
In particular, it checks for the definition of _STDDEF_H, which is defined in "stddef.h". This macro doesn't seem defined either.
So I suppose there is something I'm missing in project paths or something similar.
Does anyone know what's happening?
Have I to organize the project structure in a different way?
Let me know if you need more details to understand the problem.
Ah another thing. I've alrady did the porting of this stack on another platform based on a 32-bit microcontroller. And I didn't have this kind of problems, so I suppose it's a problem with XMOS preprocessor or some proprerties I'm not configuring correctly.