[SOLVED] 'int16_t' does not name a type

My code includes the statement
int16_t x;

The compiler throws me an error
"‘int16_t’ does not name a type"

It does this even though my code includes stdint.h

I believe int16_t is a standard type listed in stdint.h
So why would the compiler complain?

I must be missing something here. Does anyone have any suggestions?

I guess this is not part of an .ino file, so you should #include "Particle.h"

1 Like

Thanks for the suggestion ScruffR. I did as you suggested, but still got the same error message.

I think you are going to have to tell us how you are compiling your code, and post at least the failing part of your code.

The int16_t type works fine for me.

I am compiling using the Particle web-based IDE.
https://build.particle.io/build/

Here is the code portion that triggers the error.

typedef struct {
int16_t x;
int16_t y;
int16_t z;
} LIS3DHSample;

The code is taken from the ASSETTRACKERRK library.

Hi @fguptill

Stucts don’t always work well with the Wiring pre-processor used for Particle devices. Try adding this to the very top of the sketch:

#pragma SPARK_NO_PREPROCESSOR
#include "Particle.h"

You will then have to follow normal C/C++ rule for forward declaration like having function headers before you use the function etc.

2 Likes

Issue solved.

I inserted the following text as line 1 in my ino.

“// This #include statement was automatically added by the Particle IDE.”

And code compiles without errors.

1 Like

Yup, that is one of these occasions where the Particle Wiring preprocessor creates confusion :weary:

1 Like