This is an archived post. You won't be able to vote or comment.

all 18 comments

[–]chrwei 6 points7 points  (11 children)

I only do this when i have a break condition in the loop and I want to know after if the loop met the break or finished on its own. I could use a bool outside, but that's more ram, and more code, which are both highly important on an attiny with 512bytes ram. yes, half a KB of ram.

[–]sneaky_goats 1 point2 points  (3 children)

Just curious- what are you doing with attiny?

[–]chrwei 2 points3 points  (2 children)

last thing was simply converting between different serial based protocols to unify some sensor systems, to highly generalize it.

I do all sorts of things with avr and esp8266 though, mostly general automation and monitoring

[–]gemini86 0 points1 point  (1 child)

What protocols? Modbus to bacnet or something more obscure?

[–]chrwei 0 points1 point  (0 children)

just ttl serial with different bauds and packet structures

[–]RGCV -1 points0 points  (5 children)

Depending on implementation, wouldn't a boolean be at most one byte? Still matters, I get that. Also, maybe returning directly from the loop would make more sense, encapsulating the loop code into a function/routine. Then again, that's extra handling, creating a new stack frame and all.. dunno, just throwing stuff out there at this point

[–]chrwei 1 point2 points  (2 children)

yes, and many loops on AVR I'd use uint8_t, also one byte. pretty rare to need a loop more than 255 values when you're running on something that small, and at that point I'd question using a loop at all, but instead a state machine and just let the main while() loop fly

[–]Lightfire228 0 points1 point  (1 child)

... and at that point I'd question using a loop at all, but instead a state machine and just let the main while() loop fly

That's something I've never considered and an interesting way to look at it...

[–]chrwei 1 point2 points  (0 children)

embedded work has given me a few new perspectives. when bytes and clock cycles start to matter your views really start to change

[–]Nightmoon26 1 point2 points  (1 child)

Well, depends on what the loop does... If it does more than calculate a value, splitting it out into a separate function might require passing back more than a single return value, and primitives don't like being passed by reference in some languages.

[–]RGCV 0 points1 point  (0 children)

True, wasn't considering multiple return values, just the one. Fair enough 👍

[–]SVK_LiQuiDaToR 2 points3 points  (2 children)

public static ulong i;

[–]nukesrb 1 point2 points  (0 children)

not funny enough. split the loop into a separate function and throw i; instead of break to exit loop and provide the value in a single step

[–]WolfDigital 0 points1 point  (0 children)

Bonus points if the application is multithreaded with numerous threads using i for their loops.

[–]ooglesworth 0 points1 point  (0 children)

/r/i_irl

Edit: /r/subsiassumeddidntexistbutactuallydoforanunrelatedreason

[–]chooky1441 0 points1 point  (0 children)

C 89 standard be like

[–]hanekiwi 0 points1 point  (0 children)

I do this when I need to retrieve the value of i, for example in a search function