Jump to content

Newbie general C code question

Recommended Posts

I typically use them in for() and while() loops when the code may be ported to another architecture.

I think the clue finally dropped: so an example would be something where (1) you're iterating over an object that by design cannot have more than 255 elements (so it's appropriate to express the index bit length limit in its type), and (2) the code needs to run on two distinct platforms: one where an 8-bit iterator index is faster than the default word size (uint8_fast_t is roughly unsigned char or a non-standard type; is this PIC8?) and one where an 8-bit iterator index is no faster than or maybe even slower than the default word size (uint8_fast_t is unsigned int or a non-standard type). Oh, and (3) you can't trust that the compiler will be able to select the best type automatically by analyzing the iteration bounds.


That would be an iteration scenario where these types make sense to me. I can see it might happen, but it's not a situation that I've encountered enough that I'd even think of trying to optimize for it.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...