[Solved] #define weirdness

In my code if I have
<< Top of File >>
// A blank line
#define uchar unsigned char

and then later I have
uchar fred = 0;

The compiler says that uchar does not have a type.

if I remove the top blank line and make no other changes
The compiler is quite happy

Is this expected?

This is definetly not intended, but it’s also not unexpected :wink:

I expect you have this problem in an .ino file and not in a .cpp/.h file.
I’ve seen other users describing that some compile error (dis)appears whether or not there are blank lines or even single blanks in certain positions.
I myself recently had a problem where the preprocessor didn’t like my code because of this reason, but @Dave is the expert in this matter - he had put me straight on my problem.

One magic expression to remember in this case is #pragma SPARK_NO_PREPROCESSOR inside your .ino

1 Like

Thanks for the information. I have been having lots of problems with #define statements. If they are in an included .h file they are also not recognized.

I’ll try the
and see what that does.

Tried that and now it won’t compile for MANY reasons. That seems to have removed the basic functionality and reverted it to a very primitive form. As an example I get:
spi_test_cases.cpp:15:19: error: ‘D3’ was not declared in this scope
#define MRF_TX_RX D3

Are there now other includes I should add to make up for the lack of Arduino compatibility?

In this case you need to add this

#include "application.h"

This is one thing the preprocessor would do, if it wasn’t for the #pragma SPARK_NO_PREPROCESSOR

1 Like

Compiles. Is any of this written someplace that I should have known about?

Not as such in the docs, but it’s a somewhat special problem.

But in the forum if you searched for not declared in this scope this for example comes up

Or for #define this pops up

The search feature is a very handy way to find answers

But for the sake of having search work good for everyone, every poster should come up with a clear and descriptive topic headline.


I’m going to go ahead and mark this post as “solved.” If you have any additional comments feel free to respond to the thread!

1 Like