Here [1] is a page at Klover, and here [2] is one at Shure. Not sure if there's a formal specification for this, or if it's just something that manufacturers started doing.
[1]: https://www.kloverproducts.com/blog/what-is-plugin-power
[2]: https://service.shure.com/s/article/difference-between-bias-...
https://news.ycombinator.com/item?id=38790597
4B If Statements (469 comments)
If I follow your comment, you mean that he could have use a non-static global variable instead and avoid mentioning "static" keyword afterward?
Yes, the `static` can simply be dropped, it does no additional work for a single-file snippet like this.
I tried diving into Compiler Explorer to examine this, and it actually produces slightly different code for the with/without `static` cases, but it was confusing to deeply understand quickly enough to use the output here. Sorry.
Therefore it's very jarring with this text after the first C code example:
This uses a static variable to have it persist between both the compare function calls that qsort makes and the main call which (potentially) changes its value to be 1 instead of 0
This feels completely made up, and/or some confusion about things that I would expect an author of a piece like this to really know.
In reality, in this usage (at the global outermost scope level) `static` has nothing to do with persistence. All it does is make the variable "private" to the translation unit (C parliance, read as "C source code file"). The value will "persist" since the global outermost scope can't go out of scope while the program is running.
It's different when used inside a function, then it makes the value persist between invocations, in practice typically by moving the variable from the stack to the "global data" which is generally heap-allocated as the program loads. Note that C does not mention the existence of a stack for local variables, but of course that is the typical implementation on modern systems.
Your solution is perfectly fine. Even if you don't have access to strchr for some reason, the original snippet is really convoluted.
You could just write (strlen(argv[1]) > 1 && argv[1][0] == '-' && argv[1][0] == 'r') if you really want to.
Also, the use of a convoluted `if` to conditionally assign a literal boolean is a code smell (to me), I would drop the `if` and just use:
in_reverse = argc > 0 && argv[1][0] == '-' && argv[1][1] == 'r';
if a more forward-thinking/strict check is not needed.I vaguely remember a reference to some balance game as the origin story for the Guru Meditation, but that was so long ago and I never looked it up!
Meta: it would have been nice to include this reference in the submission title, since it's least as interesting as the fact that the peripheral was for the Atari 2600. Something like "The Joyboard: Atari 2600 balance peripheral that inspired Guru Meditation", perhaps. Probably too late now, and this is not exactly tearing down the front page, anyway. :)
Thanks!
This will serve a similar use case just on a bigger scale.
This:
struct Vec3* v = malloc(sizeof(struct Vec3));
is better written as:
struct Vec3 * const v = malloc(sizeof *v);
I don't love this. Other people are going to think you're only allocating a pointer. It's potentially confusing.It's not possible to know C code and think that
sizeof *v
and sizeof v
somehow mean the same thing, at least not to me.