4 ms·
> -Wall turns on a group of warnings that can catch common mistakes. I appreciate modern languages, which just catch this at compile time, without making peopl
by 38 3y ago
> -Wall turns on a group of warnings that can catch common mistakes.
I appreciate modern languages, which just catch this at compile time, without
making people jump through hoops. for example I can just run "go build", and
this wont even compile:
package main
func main() {
println("Program run!")
i := 10 // i declared and not used
}
- flohofwoe 3y agoDeclaring '-Wall -Wextra -Werror' on the compiler command line isn't exactly "jumping through hoops" though. This should be the default of course, but this will just bring out the pitch forks because people have different opinions (for instance this innocent unused-variable-error in Go is currently by far the most controversial feature in Zig).
- spc476 3y agoAnd then you hit: warning: ISO C forbids assignment between function pointer and `void *' Which, while true, is allowed (and in fact, required by) POSIX. Of course, not passing "-pedantic" will suppress that warning, but you'll also suppress other, critical warnings. Okay, I'll put away my pitchfork now.
- pjmlp 3y agoSuch warnings might save some hours of pain when writing cross platform code.
- LoganDark 3y agoThis isn't really an innocent Go feature, either. I have a meme saved somewhere that's basically "no, fuck you, variable declared but not used".
- IshKebab 3y agoI agree, but that is not the most compelling example to be honest. I think a better one is my nemesis: int foo() {} This is not an error or even a warning by default! Worse, even if you have enabled warnings, it can cause stack corruption and crazy insane behaviour in a different file. I've lost hours to this because I was working on code without `-Werror`, I didn't see the warning, and incremental compilation meant the offending file was never recompiled (I was trying to fix the error in a different file). Of course modern languages don't have this insanity.
- LoganDark 3y agoCould this explain the miscompilation I was experiencing on macOS some years ago where I forgot a `return` statement, the compiler didn't give a single fuck and spit out an executable anyway, and I spent hours in a debugger wondering how the hell I found myself in random completely invalid instructions for no reason? Took hours, perhaps even days to track down. I did it by spamming single-step until it stopped being able to find the line that was currently executing.
- deleted 3y ago[deleted]
- flohofwoe 3y ago> This is not an error or even a warning by default! It depends on the compiler, for instance in Clang this is part of the default warning set: https://www.godbolt.org/z/bKnq456eK https://www.godbolt.org/z/bKnq456eK
- vbezhenar 3y agogcc has that warning as well (not enabled by default, but enabled with -Wall). However gcc does not have a warning that I'm supposed to write `int foo(void){}` (if we're talking about C) which is real issue.
- astrange 3y agoNot true anymore in C2x, () means (void) now. The missing return type is still an issue though.
- flohofwoe 3y agoAh right. Clang will warn if you actually try to call such a () function with arguments: https://www.godbolt.org/z/qEa55PdG9 https://www.godbolt.org/z/qEa55PdG9 Both GCC and MSVC don't care though.
- vbezhenar 3y agoThat's a terrible example and I hate go for that. It makes writing code iteratively huge PITA. It's error to turn warnings into error. My final code is free of warnings, however having a warning during development, especially so innocent like unused variable should totally be fine. Because I just wrote this code and I need to test that something works and then I'll write the next part.
- 38 3y agosorry you feel that way. I agree its annoying, but I think ultimately it makes for better code. you can always comment out the line, or add a "_ = i" or similar.