Using C Standard Variable Types
This can be essential if using a 32bit Arduino and needing a 16bit varaible or for any code which needs to be sure what size and int variable is
#include <stdint.h>
bool
boolean
char
-128 to 127
byte
0 to 255
short
unsigned short
int
unsigned int
long
unsigned long
long long
unsigned long long
float
double
int8_t
-128 to 127
uint8_t
0 to 255
int16_t
-32,768 to 32,767
uint16_t
0 to 65,535
int32_t
-2,147,483,648 to 2,147,483,647
uint32_t
0 to 4,294,967,295
int64_t
−9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
uint64_t
0 to 18,446,744,073,709,551,615
Handy Typedefs To Use
#include <stdint.h>
typedef bool BOOL;
typedef uint8_t BYTE;
typedef int8_t INT8;
typedef uint8_t UNINT8;
typedef int16_t INT16;
typedef uint16_t UINT16;
typedef int32_t INT32;
typedef uint32_t UNINT32;
typedef int64_t INT64;
typedef uint64_t UINT64;
Display Memory Size Of All C Types
#include <stdint.h>
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("sizeof(byte)=");
Serial.println(sizeof(byte));
Serial.println();
Serial.print("sizeof(char)=");
Serial.println(sizeof(char));
Serial.println();
Serial.print("sizeof(short)=");
Serial.println(sizeof(short));
Serial.println();
Serial.print("sizeof(int)=");
Serial.println(sizeof(int));
Serial.println();
Serial.print("sizeof(long)=");
Serial.println(sizeof(long));
Serial.println();
Serial.print("sizeof(long long)=");
Serial.println(sizeof(long long));
Serial.println();
Serial.print("sizeof(bool)=");
Serial.println(sizeof(bool));
Serial.println();
Serial.print("sizeof(boolean)=");
Serial.println(sizeof(boolean));
Serial.println();
Serial.print("sizeof(float)=");
Serial.println(sizeof(float));
Serial.println();
Serial.print("sizeof(double)=");
Serial.println(sizeof(double));
Serial.println();
Serial.print("sizeof(int8_t)=");
Serial.println(sizeof(int8_t));
Serial.println();
Serial.print("sizeof(int16_t)=");
Serial.println(sizeof(int16_t));
Serial.println();
Serial.print("sizeof(int32_t)=");
Serial.println(sizeof(int32_t));
Serial.println();
Serial.print("sizeof(int64_t)=");
Serial.println(sizeof(int64_t));
Serial.println();
Serial.print("sizeof(uint8_t)=");
Serial.println(sizeof(uint8_t));
Serial.println();
Serial.print("sizeof(uint16_t)=");
Serial.println(sizeof(uint16_t));
Serial.println();
Serial.print("sizeof(uint32_t)=");
Serial.println(sizeof(uint32_t));
Serial.println();
Serial.print("sizeof(uint64_t)=");
Serial.println(sizeof(uint64_t));
Serial.println();
Serial.print("sizeof(char*)=");
Serial.println(sizeof(char*));
Serial.println();
Serial.print("sizeof(int*)=");
Serial.println(sizeof(int*));
Serial.println();
Serial.print("sizeof(long*)=");
Serial.println(sizeof(long*));
Serial.println();
Serial.print("sizeof(float*)=");
Serial.println(sizeof(float*));
Serial.println();
Serial.print("sizeof(double*)=");
Serial.println(sizeof(double*));
Serial.println();
Serial.print("sizeof(void*)=");
Serial.println(sizeof(void*));
Serial.println();
while (1)
delay(10000);
}
7 years ago
Thanks for this reference table