I wonder why the following minimal example sketch doesn't compile (unknown type name 'uint16_t'
):
sketch_does_not_compile.ino
:
#include "myheader.h"
void setup() {
char a[]="hello world";
uint16_t l=str_len(a);
Serial.println(l);
}
void loop() {}
myheader.c
:
uint16_t str_len(char* input_string) {
uint16_t i=0;
while (input_string[i++]!='\0');
return i;
}
myheader.h
:
#include "myheader.h"
uint16_t str_len(char* input_string);
Compilation fails with:
myheader.c: At top level:
myheader.c:3:1: error: unknown type name 'uint16_t'
uint16_t str_len(char* input_string);
^
exit status 1
unknown type name 'uint16_t'
Using uint16_t
in the .ino-file directly like in the sketch below compiles fine.
sketch_compiles.ino
:
uint16_t str_len(char* input_string) {
uint16_t i=0;
while (input_string[i++]!='\0');
return i;
}
void setup() {
char a[]="hello world";
uint16_t l=str_len(a);
Serial.println(l);
}
void loop() {}
What am I missing?
#include <stdint.h>