Page 1 of 1

Problems with macros and preprocessor

Posted: Thu Oct 01, 2020 1:38 pm
by nick
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:

Code: Select all

#ifndef MY_HEADER
#define MY_HEADER    "my_header.h"
#endif
And in another .h file (in the same folder) they wrote:

Code: Select all

#ifdef MY_HEADER
#include MY_HEADER
#endif
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.

Re: Problems with macros and preprocessor

Posted: Fri Oct 02, 2020 10:24 am
by nick
For problem number 2 I've just noticed that in "stddef.h" of XMOS the macro __STDDEF_H is defined with 2 underscores at the beginning.
It is usually defined with just 1 underscore, instead.

That's why my stack doesn't see it.

Re: Problems with macros and preprocessor

Posted: Mon Oct 05, 2020 2:16 pm
by akp
One can't help but wonder if that's a problem with the 3rd party stack and not with XMOS C toolchain... I really don't know what the C standards say.

Re: Problems with macros and preprocessor

Posted: Mon Oct 05, 2020 4:37 pm
by nick
Me too, I found it in a "stddef.h" but didn't check C standard. I modified my stack.