#ifdef INTTYPES
#include <stdint.h>
#else
#define INTTYPES
/*unsigned types*/
typedef unsigned char uint8_t;
typedef unsigned int uint16_t;
typedef unsigned long uint32_t;
typedef unsigned long long uint64_t;
/*signed types*/
typedef signed char int8_t;
typedef signed int int16_t;
typedef signed long int32_t;
typedef signed long long int64_t;
#endif
Programmers are trying to push the wording.... An Int is so ambiguous!! It really means integer value ( whole number ) The reason it was pushed into the world as a 16 bit whole number was that Intel and Zilog made register pairs so you could access 16 bit addresses... 64k used to be the building blocks... When expanded memory was introduced to the AT series PC it was through a 64k window...
On a 8 bit machine the integer is 8 bit, on a 16 bit.. yada yada yada.... Words, Long words, Double long words are easier to remember....
On a 8 bit machine the integer is 8 bit, on a 16 bit.. yada yada yada....
Hi again,
Well that's another mystery, because the Atmel 328P chip is 8 bit, but the Arduino lib wants to make "int" 16 bits
I'll just have to remember to be more specific from now on. I'll have to go over some of my other code now too to make sure there are no screw ups like this in them either. At least i know now.
Same result in XC8...I ran quick test:
printf("\n%d", sizeof(1000));
printf("\n%d", sizeof(200));
printf("\n%d", sizeof(40000));
printf("\n%d", sizeof(4000*4000));
This prints out:
2
2
4
2
.. So the 40 000 is treated as Long, but 4000*4000 is two int variables multiplied and truncated.
Compiled with avr-gcc (same compiler that Arduino IDE uses) -std=gnu99 flag on.
avr-gcc and avr-libc documentation could be a better source than Arduino IDE documentation for this kind of problems.
https://gcc.gnu.org/wiki/avr-gcc
https://www.nongnu.org/avr-libc/user-manual/modules.html
You can force the int to be 8-bits if you want, but I would not recommend doing that:
"With -mint8 int is only 8 bits wide which does not comply to the C standard. Notice that -mint8 is not a multilib option and neither supported by AVR-Libc (except stdint.h) nor by newlib"
I always use standard integer types, then you know exactly what kind of variable you get:
#include <stdint.h>
uint8_t variableUnsigned;
int8_t anotherVariable;
int16_t variable16bits;
int32_t largeVariable;
int64_t hugeVariable;
https://www.nongnu.org/avr-libc/user-manual/group__avr__stdint.html
I ran quick test:
printf("\n%d", sizeof(1000));
printf("\n%d", sizeof(200));
printf("\n%d", sizeof(40000));
printf("\n%d", sizeof(4000*4000));
This prints out:
2
2
4
2
.. So the 40 000 is treated as Long, but 4000*4000 is two int variables multiplied and truncated.
Compiled with avr-gcc (same compiler that Arduino IDE uses) -std=gnu99 flag on.
avr-gcc and avr-libc documentation could be a better source than Arduino IDE documentation for this kind of problems.
https://gcc.gnu.org/wiki/avr-gcc
https://www.nongnu.org/avr-libc/user-manual/modules.html
You can force the int to be 8-bits if you want, but I would not recommend doing that:
"With -mint8 int is only 8 bits wide which does not comply to the C standard. Notice that -mint8 is not a multilib option and neither supported by AVR-Libc (except stdint.h) nor by newlib"
I always use standard integer types, then you know exactly what kind of variable you get:
#include <stdint.h>
uint8_t variableUnsigned;
int8_t anotherVariable;
int16_t variable16bits;
int32_t largeVariable;
int64_t hugeVariable;
https://www.nongnu.org/avr-libc/user-manual/group__avr__stdint.html
Would this "offset=offset+13.*3600"; //set 13 hours (in seconds)" or something similar work?
The little addition of the decimal point. Used to do stuff like a = 1.*5000*5000 long ago in a different era.
Would this "offset=offset+13.*3600"; //set 13 hours (in seconds)" or something similar work?
The little addition of the decimal point. Used to do stuff like a = 1.*5000*5000 long ago in a different era.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?