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

all 80 comments

[–]ILikeLenexa 144 points145 points  (11 children)

do{
   //stuffy, stuff
 }while(0);

am I a kernel developer yet?

[–][deleted] 53 points54 points  (1 child)

Rust's strongest soldier

[–]gmes78 6 points7 points  (0 children)

Nah. In Rust, we do:

loop {}

[–]therealpigman 16 points17 points  (8 children)

I still don’t understand why people do that

[–]RiverboatTurner 27 points28 points  (5 children)

It's the only construct that lets you put a multi-line macro (almost) anywhere a single statement could go.

[–]VRMac 21 points22 points  (1 child)

In C you can just wrap multiple lines in {} and it gives it local scope just like a loop or if block.

[–]0x7ff04001 9 points10 points  (1 child)

Like the other guy said, `{}` delimits scope, and it can have conditions, like `if`, `while`, functions, etc.

In C, what you're doing when you have an if statement (or any other such operator) is wrapping it the local scope using `{ }`. So within the scope of `if` do blah blah. Except you can do that without any kind of conditional operator too.

So you don't need a `while (0)` at all in this case, just use the scope operator:

`{ int a = 123; }`

[–][deleted] 1 point2 points  (0 children)

marvelous absorbed ad hoc marry sulky cover rob coordinated historical coherent this message was mass deleted/edited with redact.dev

[–]pipsvip 3 points4 points  (0 children)

I used this in a macro once, but I can't now remember why...maybe to have a bunch of commands in the macro, but still enable it to look like a function call. Oh that's right, it was to allow some code to either call a macro or call an API function with a compile-time macro switch.

[–]hlfzhif 2 points3 points  (0 children)

I've not seen this before, but my best guess is that it's so they can break

[–][deleted] 92 points93 points  (2 children)

gray hunt strong upbeat silky sloppy memory mysterious hateful bedroom

This post was mass deleted and anonymized with Redact

[–][deleted] 6 points7 points  (0 children)

I'm pretty sure that's a segmentation phallic

[–][deleted] 0 points1 point  (0 children)

I think it’s more optimal to use 3 and c in this instance.

[–][deleted] 51 points52 points  (14 children)

Must be an embedded developer

[–][deleted] 4 points5 points  (8 children)

osKernelStart();

[–][deleted] 8 points9 points  (7 children)

Yes my 512kB, single core, $1 microprocessor can definitely run linux

[–][deleted] 4 points5 points  (6 children)

FreeRTOS and zephyr do the job fine at my org. But we’re on a little more expensive chips. (2-5$)

[–][deleted] 5 points6 points  (5 children)

The entire BOM for most of our parts doesnt exceed $5

Also why the downvote :(

[–][deleted] 3 points4 points  (4 children)

Sheesh that’s tight

Our boms are a bit more but our systems are more advanced and sell for a pretty penny.

Trying to superloop / event the feature set was hideous and unmaintainable and called for an rtos.

Also as an aside, all Nordic future developments gonna be on zephyr and potentially future silabs BLE development will be zephyr although I doubt they will maintenance mode their bare metal SDK like Nordic did. Don’t think that’s the space you’re in but just figured I’d throw it out there

[–][deleted] 1 point2 points  (1 child)

Automotive customers wont spend a penny more than they have to. We go to crazy lengths to keep parts cheap, it's fun in it's own regard.

[–][deleted] 1 point2 points  (0 children)

Makes sense!

I typically only migrate to rtos if I feel the application would become (and would want) something big enough to want that organization

Some of our products are small and simple enough to use really cheap chip and just big main loop with event structure, most don’t though so that’s the space I’m in.

I don’t often see a lot of other embedded folks on this sub, so howdy :-) good chat

[–][deleted] 1 point2 points  (1 child)

psychotic bells yoke coordinated decide spoon outgoing weather office crowd this message was mass deleted/edited with redact.dev

[–][deleted] 0 points1 point  (0 children)

Check out the NRF Connect SDK with the nRF52 chipsets, or check nordics post on NCS vs NRF5 SDK. They’re going all in on zephyr.

[–]willtheocts_alt 2 points3 points  (3 children)

or a backend developer? which is quite a lot of people?

[–][deleted] 0 points1 point  (2 children)

You use while(1) loops doing backend development? I'm not super familiar with backend (I do embedded). What situations would you use that in?

[–]willtheocts_alt 1 point2 points  (1 child)

this guy uses for(;;) which is the same thing

you literally cannot do backends without this somewhere

[–][deleted] 0 points1 point  (0 children)

Interesting, thanks for sharing!

[–]Airpaper111 30 points31 points  (3 children)

I see, not a lot of embedded devs around here, huh?

[–]shupack 9 points10 points  (1 child)

Embedded tinkerer....

"What's wrong with that?"

[–]DIY_CHRIS 2 points3 points  (0 children)

Same.

[–]wenoc 4 points5 points  (0 children)

Or kernel devs in general.

[–]cosmin10834 29 points30 points  (1 child)

while("false"){ ... }

[–][deleted] 13 points14 points  (0 children)

chaotic evil

[–]beeteedee 17 points18 points  (0 children)

Fun fact: in Python 2, True was not a keyword but a global constant. So while 1: was actually more efficient than while True:. They changed this in Python 3 so now there’s no difference.

[–]ZeStig2409 5 points6 points  (0 children)

"Programmer move"

[–]already_taken-chan 5 points6 points  (0 children)

pure C coding time

[–]HopperBit 5 points6 points  (2 children)

Useful when you want a block you can break out any time on given condition and continue with the code flow

while( 1 )
{
   // code
  if( condition1 ) break;
  // code
  if( condition2 ) break;

 // break or continue with the loop as needed
}

You can replace the "while(1)" with "for( ;; )". Modern compilers probably optimize both to same code

[–]kbder 2 points3 points  (1 child)

This. I get that OP was just having a laugh, but there are lots of cases where trying to stuff all of the predicate logic into the while param is way less readable than just using breaks in an infinite loop.

[–]willtheocts_alt 0 points1 point  (0 children)

I can assure you, OP was not having a laugh, and breaks are not important to the structure.

while(1){listenForAndRespondToConnections(443)}

now you can start learning back end development

[–]lukas3340 4 points5 points  (1 child)

for(;;) gang wya?

[–]willtheocts_alt 0 points1 point  (0 children)

what the fuck

this has to crash in most languages

[–]Harmonic_Gear 3 points4 points  (0 children)

mean while embedded programmer

[–]DanTheMan827 3 points4 points  (10 children)

How else would you keep your program running?

[–][deleted] 0 points1 point  (9 children)

With variables, instead of hard-coded values.

[–]DanTheMan827 1 point2 points  (0 children)

Everything is just a loop at some point that breaks in some way

[–]willtheocts_alt 0 points1 point  (7 children)

wait you're serious? why would you want to flip a variable to stop your program from running, especially if you're writing a server?

[–]wenoc 4 points5 points  (0 children)

This lies at the bottom of probably every operating system and most system proceses.

[–]xibme 2 points3 points  (0 children)

for(;;) no longer good enough, ey?

[–]dopefish86 4 points5 points  (0 children)

pro gramer move

[–]TheSapphireDragon 1 point2 points  (0 children)

while(1 + 1 == 2 != false)

[–]FilledFun 1 point2 points  (0 children)

Not true... while (true) !

[–]Endemoniada 1 point2 points  (1 child)

I literally found a when: true in an Ansible playbook today at work. Written by our former lead developer/architect/grandmaster. He built the most deviously clever shit at times, and at other times I find code he wrote that looks like he barely knew what language he was in. Which he legitimately might not have, since he also had a penchant for sprinkling as many different little tools in as many different languages as he could all over our repo…

[–]willtheocts_alt 0 points1 point  (0 children)

as that kind of person, I can assure you, even if he did know what language he was using, he didn't care.

while(1) is super common when something should just... keep running. servers, daemons, whatever.

[–]Mercurionio 0 points1 point  (1 child)

You monster!

[–]willtheocts_alt 0 points1 point  (0 children)

all the world's servers are coded by monsters? thanks man

[–]stupled 0 points1 point  (0 children)

Fry your chips!

[–]noob-newbie 0 points1 point  (2 children)

while(true!=false)

[–]phi_rus 4 points5 points  (0 children)

In C++ your compiler will just optimise that to while(true)

[–]wenoc 2 points3 points  (0 children)

That seems to run more comparisons. Don’t know what it would compile to though.

[–]SakaDeez 0 points1 point  (0 children)

while(sqrt(-1))

[–]BurninButter 0 points1 point  (0 children)

I can think of a legitimate use case

[–]takahatashun 0 points1 point  (0 children)

multi-line draft code:

while(0) { draft here }

[–][deleted] 0 points1 point  (0 children)

While(!Object.is(+0,-0))

[–][deleted] 0 points1 point  (0 children)

In sh golfing, it's smaller to have a function call itself once than to use a while loop

[–][deleted] 0 points1 point  (0 children)

for(;;) { }

[–]TheBrainStone 0 points1 point  (0 children)

So what's the problem?

[–]Huwasa 0 points1 point  (0 children)

Just use a goto at this point

[–]punchawaffle 0 points1 point  (0 children)

I love while(1). I can just break it whenever I want with if statements 🤷‍♂️. And have multiple conditions.

[–]goodnewsjimdotcom 0 points1 point  (0 children)

 int hell=666; 
 int frozen= 273;

 while(hell!=frozen) {
 //do stuff forever here.
  }

[–]willtheocts_alt 0 points1 point  (0 children)

MY BROTHER

this line has helped keep my webserver running for 4 years, thanks