Pages: [1]   Go Down
Author Topic: only ever returns byte; uses int  (Read 488 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I noticed that only returns one byte, as designed (and according to the docs:, but still uses an int memory location, of which the first byte will always be empty.

Shouldn't it always return a byte? Or, is this to allow for certain compatibilities somewhere?
« Last Edit: June 25, 2007, 12:17:48 am by jeffwheeler » Logged

Offline Offline
Faraday Member
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It needs something larger than a byte for the same reason getchar() from stdio needs to return something larger than a char - so you've got a way to represent some non-character data, namely the EOF condition.

A byte can represent 256 values, namely the 256 extended ASCII values.  The leaves no room for an EOF flag, so we need a larger type that will hold 256 values for a byte, plus one more value for EOF.


Pages: [1]   Go Up
Jump to: