The documentation and function show than analogRead returns an int. Two low & high uint8_t bytes appear to be automatically cast to int when the function returns.
Is this based on the return type of the function or the type of the variable we're assigning to?
Can analogRead only ever return positive numbers anyway?
unsigned int a = analogRead(A0);
unsigned int a = (unsinged int)analogRead(A0);
Snippet from wiring_analog.c
int analogRead(uint8_t pin)
{
uint8_t low, high;
...
// combine the two bytes
return (high << 8) | low;
}
The signature of the function shows it returns an int and the line above Combines 2 bytes into the least significant and most significant bits of the int. It is signed but on your standard arduino will report between 0 and 1023.
Then depending on what you assign the result to, the compiler will use Promotion rules to define what to do and how to cast things.
Can analogRead only ever return positive numbers anyway?
analogRead returns the value from the register of the AtoD converter, 0 to 1023, a 10bit register and always positive.
0 to 1023 representing 0V to Vref volts.