@LukeAlmighty Single = means assign. That means you can assign in an if statement.

@matrix @LukeAlmighty C famously also supports that, it's been a source of numerous backdoors and most linters tend to forbid it.
Follow

@lanodan @LukeAlmighty @matrix Linters just warn you if you don't wrap it in extra ()

· · Web · 1 · 0 · 1

@applejack @LukeAlmighty @matrix

There is no such thing as consistent behavior for linters and it’s rather well known that linux kernel has it’s own, but well, the horribly old one called splint still does by default:

$ cat hello.c #include <stdio.h> // puts int main(int argc, char *argv[]) { (void)argc; if ((argv[1] = "--help")) { (void)puts("."); } (void)puts(argv[1]); return 0; } $ make hello CFLAGS="-Wall -Wextra" cc -Wall -Wextra hello.c -o hello hello.c: In function ‘main’: hello.c:6:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses] 6 | if (argv[1] = "--help") { | ^~~~ $ ./hello . --help $ splint hello.c Splint 3.1.2 --- 03 Feb 2021 hello.c: (in function main) hello.c:5:2: Statement has no effect: (void)argc Statement has no visible effect --- no values are modified. (Use -noeffect to inhibit warning) hello.c:6:7: Observer storage assigned to unqualified reference: argv[1] = "--help" Observer storage is transferred to a non-observer reference. (Use -observertrans to inhibit warning) hello.c:6:17: Storage becomes observer Finished checking --- 2 code warnings $

@applejack @LukeAlmighty @matrix That’s probably because assigning into a while is rather common, for example while((c = getopt(argc, argv, ":d:u")) != -1) is idiomatic in C but I wouldn’t be surprised that the linux kernel linter warns about it.

@lanodan @LukeAlmighty @matrix I'm not a kernel dev. GCC and Clang also behave in the same way with -Wall just suggesting ()

@applejack @LukeAlmighty @matrix Kernel dev isn't really a thing I do either (specially because I hate having to deal with boot time problems) but I'm still a bit familiar with it because of needing to apply some patches and few times adapt them from one version to another.
Sign in to participate in the conversation
Game Liberty Mastodon

Mainly gaming/nerd instance for people who value free speech. Everyone is welcome.