Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Soricidus
Oct 21, 2010
freedom-hating statist shill

Delta-Wye posted:

I usually use the smallest datatype available. If I know a value will fit into a char, I'll use a char, even if I am not particularly memory constrained. That is to say I don't just hold ASCII characters in a char datatype, but use it as a 8-bit integer.
It's usually preferable to use the explicit 8-bit types from <stdint.h>, i.e. int8_t or uint8_t. More typing than "char", but less typing than "unsigned char", and it can make your code clearer if e.g. you can start distinguishing between "char*" (a string) and "uint8_t*" (byte data).

Delta-Wye posted:

Supposedly this doesn't work very well on a platform like the MSP430. I was told that the 16-bit processors will read a 16-bit value out of memory, mask it to an 8 bit value, do the required operation, then have to mask it again with the contents of memory when storing it.
I'm not an MSP430 expert, so take this with a pinch of salt, but I don't think this should be a showstopper for you since IIRC its instruction set includes 8-bit operations as well as 16-bit. You will probably see masking if the compiler has to convert between 8-bit variables and ints. It'll depend on your code whether this happens enough to make any difference.

With more confidence I will suggest that <stdint.h> can help here as well. For example, it provides the type "uint_fast8_t", which in theory translates to whatever datatype will store an 8-bit quantity in the most computationally efficient way. In practice you're at the mercy of your compiler vendor. If you don't trust the compiler, you'll have to look at the assembly.

Adbot
ADBOT LOVES YOU

Soricidus
Oct 21, 2010
freedom-hating statist shill

No Gravitas posted:

C) Does not run on Windows, game over. :(
D) Comedy "Wine + Valgrind" option.

  • Locked thread