And what about 'Rust', you ask, since it claims to solve all the problems of C.
doc.rust-lang.org
Oh dear... still the same old crap! 
Oh dear indeed. "..=" ".. , expr.. "And what about 'Rust', you ask, since it claims to solve all the problems in C.
Oh dear... still the same old crap!B - Operators and Symbols - The Rust Programming Language
doc.rust-lang.org
![]()
if (var = 10) {... ; }
For 30 years I have never made bug typing '=' instead of '=='. And again - there is warning message to protect you from such rare bug. Reading and writing 'if ( 5 < a )' is more significant risk of logical errors.The thing you're trying to protect against is accidentally typing '=' instead of the intended '==' or '!=' (or '<=' or '>='), which is a well-known classic bug in C. Or a random pigeon flying in through the window and pecking at the delete key when the cursor is under the '!' or '<' or '>' character. Pesky pigeons! Why is it a problem? Because the incorrect code will compile with no warnings!
See FreeBSD (Linux kernel, etc.) source code and think how it works without =/== "protection".Trust me, when you're working on codebases of millions of lines of C code, those kinds of bugs are guaranteed to occur, and furthermore they will be a huge pain in the elbow to debug!
Which is only useful if one actually pays attention to compiler warnings or set compiler flags so "warnings are errors and cause compilation to stop".And again - there is warning message to protect you from such rare bug.
This is his/her problem. Maybe better to program in python or javascript. C language requires some precision and attention on details.Which is only useful if one actually pays attention to compiler warnings
#include <stdio.h>
int main(int argc, char *argv[]) {
int var;
if ( var = 10 ) {
printf("assigned var=10\n");
}
}
#include <stdio.h>
int main(int argc, char *argv[]) {
int var;
if ( (var = 10) ) {
printf("assigned var=10\n");
}
}
Correct.C language requires some precision and attention on details.
I don't disagree with this, but a lot of times it's not isolated to an individual; sometimes it is institutional. "Need to get this product out the door so speed up dev as much as possible" and people that want to follow a better process are seen as "blockers".This is his/her problem. Maybe better to program in python or javascript. C language requires some precision and attention on details.
It is a common construct to have a compound conditional expression where the sub-expressions are delineated by parentheses as a matter of style for readability, egAnd what? Double parenthesis syntax says this "I know this looks like incorrect assignment but it is not". Or maybe somebody will accidentally type 2 parenthesis and not see them? And later he/she will enter = instead of == and not see it?
No-one is saying write things like '(5 < a)', in fact I've never seen that in any code I've looked at! As for a modern trend... I've been writing code that way to mitigate the '=' is not '==' bug for decades. I haven't heard of this 'pretend safe programming in C' you talk about either; in fact I'm pretty sure I was taught this particular mitigation during my original C programming course at univ, back in the '80's.I will repeat - writing things likeif ( 5 < a )is modern trend pretending it is "safe programming". And again - look at gcc/clang source code and think why their programmers don't use the trend. Maybe they are not good.
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main(int argc, char *argv[]) {
int rc=-1;
if (argc != 2) { // changed order to keep 6502 happy
fprintf(stderr, "Error: test <filename>\n");
} else {
FILE *fptr;
fptr = fopen(argv[1], "r+");
if (fptr != NULL) { // changed order to keep 6502 happy
printf ("opened file: %s\n", argv[1]);
fclose (fptr);
// strictly we should check the fclose return code here
printf ("closed file: %s\n", argv[1]);
rc = 0;
} else {
fprintf(stderr, "failed to open file: %s - %s\n",
argv[1],
strerror(errno));
}
}
return rc;
}
For the record, I've never had to suffer reading anyone doing 5<a. We're talking about equality comparison vs assignment here and how in C/C++ the mistake can slip thru if you don't reverse the operators like I suggest, but then I'm a dinosaur who is set in his ways.There is compiler warning for this. It is stupid trend blindly followed by many people. Most stupid is to compare "if ( 5 < a )" instead of "if ( a > 5 )".