Close

What? That compiled?!

A project log for Holiday 8-bit ^2 LED Ornament

An 8x8 LED matrix animated ornament powered by an ATtiny85

toddTodd 12/18/2017 at 21:474 Comments

Hmm, when you copy and paste an enum into a `switch` so you don't get the names wrong but then you forget to add some keyword back... can you find it? ;)

Surprisingly, this compiles (but doesn't work as expected)... and I'm not a C expert enough to know why. But wow, that stumped me for a couple hours!

Discussions

Todd wrote 12/20/2017 at 02:18 point

Ah! I had no idea C had labels and goto! Yikes. 

I <3 JS closures.

  Are you sure? yes | no

Thomas wrote 12/19/2017 at 06:26 point

That's no problem because a void function doesn't need a return statement. If your function were int it would work, too, but the result is undefined. I'm not sure but I think that most compilers I worked with issued a warning when I forgot to return a value.

  Are you sure? yes | no

Todd wrote 12/19/2017 at 07:44 point

Perhaps I misunderstand, but it's not the void function I was wondering about the lack of case keywords. Going back I do see warnings, but still surprised it compiled without error. Thanks for the response!

  Are you sure? yes | no

Thomas wrote 12/19/2017 at 21:35 point

Ah, now I see it :-) Labels, a relic of the Assembly age, sometimes useful for a clean escape, but not a thing one would expect in a switch statement. Nothing compared to the wonders of a JavaScript closure.

  Are you sure? yes | no