Problems with macros and preprocessor

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
nick
Active Member
Posts: 35
Joined: Tue Jan 07, 2020 10:35 am

Problems with macros and preprocessor

Postby nick » 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:

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.
nick
Active Member
Posts: 35
Joined: Tue Jan 07, 2020 10:35 am

Postby nick » Fri Oct 02, 2020 10:24 am

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.
User avatar
akp
Respected Member
Posts: 449
Joined: Thu Nov 26, 2015 11:47 pm

Postby akp » Mon Oct 05, 2020 2:16 pm

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.
nick
Active Member
Posts: 35
Joined: Tue Jan 07, 2020 10:35 am

Postby nick » Mon Oct 05, 2020 4:37 pm

Me too, I found it in a "stddef.h" but didn't check C standard. I modified my stack.

Who is online

Users browsing this forum: No registered users and 3 guests