today in C nonsense: a declaration is available in it's initialization expression:
-
today in C nonsense: a declaration is available in it's initialization expression:
int some_func(void) {
int a = a;
return a;
} -
today in C nonsense: a declaration is available in it's initialization expression:
int some_func(void) {
int a = a;
return a;
}@karolherbst iirc gcc can catch it with -Winit-self -
@karolherbst iirc gcc can catch it with -Winit-self
@a1ba C would be 100 times better if such warnings would be errors instead by default
-
@a1ba C would be 100 times better if such warnings would be errors instead by default
@karolherbst I kinda like that modern good compilers allows forcing warnings into errors and also has a lot of diagnostics...
but also it's sad that useless tricks like this not strictly violating the standard and compilers wouldn't turn such diagnostics into errors by default -
@karolherbst I kinda like that modern good compilers allows forcing warnings into errors and also has a lot of diagnostics...
but also it's sad that useless tricks like this not strictly violating the standard and compilers wouldn't turn such diagnostics into errors by default@a1ba @karolherbst by "not strictly violating the standard you mean this is not UB? i thought it was
-
@karolherbst I kinda like that modern good compilers allows forcing warnings into errors and also has a lot of diagnostics...
but also it's sad that useless tricks like this not strictly violating the standard and compilers wouldn't turn such diagnostics into errors by default@a1ba @karolherbst And well modern C compilers have also gradually been turning warnings into errors, of course gradual because C is way too critical and widespread to have massive breaking changes from one compiler version to the other. -
@a1ba @karolherbst by "not strictly violating the standard you mean this is not UB? i thought it was
@mildsunrise @karolherbst that's my opinion but I don't think UB is supposed to be treated like standard violation.
Because if it was, such tricks would've been prohibited, especially in the newer revisions of the standard. But probably that's just me interpreting the word "violation" differently. -
@a1ba @karolherbst And well modern C compilers have also gradually been turning warnings into errors, of course gradual because C is way too critical and widespread to have massive breaking changes from one compiler version to the other.@lanodan @karolherbst my "favourite" useless feature of an old C is implicit function declaration. Not sure if it became error by default, because everybody sane just force it into an error by their own.
-
@karolherbst iirc gcc can catch it with -Winit-self
-
No, gcc and clang return 0
@HugeGameArtGD @karolherbst you mean exit successfully? Of course, because that's just the warning.
-Werror=xxx forces diagnostic to be an error. -
@HugeGameArtGD @karolherbst you mean exit successfully? Of course, because that's just the warning.
-Werror=xxx forces diagnostic to be an error. -
@a1ba @karolherbst
I don't get any warning, compiles fine and returns 0#include <stdio.h>
int some_func(void) {
int a = a;
return a;
}int main() {
printf("%d", some_func());
}