So you think you know C? (2016)
251–260 of 344 posts
Re: So you think you know C? (2016)
#252Re: So you think you know C? (2016)
#253Earlier quoted context omitted.
You can easily get bitten by at least one of those examples just by compiling your application written on x86 to ARM to get it running on Android, so not sure if it's as esoteric as you think.
Or on different compilers, or the same compiler with different options, etc.
Re: So you think you know C? (2016)
#254Earlier quoted context omitted.
> You can get along just fine in C++ without knowing the exact aliasing rules from C Nope, you can't. These are exactly the things that introduce undefined behavior (i.e. total breakage) if you aren't very careful about what you're doing at all times. Don't take my word for it, check out what the C++ designers themselves state about the issue in the C++ Core Guidelines. C/C++ is far from simple, and thinking that you…
You are absolutely right, but my point is that when you do modern C++, in the application code, it is very unlikely that you need to use reinterpret_cast in your code, and therefore you don't need to know all the subtlety about it. So despite C++ being more complex than C, if you limit yourself to some practical subset, it is actually easier than C.
And it doesn't work in practice.
Re: So you think you know C? (2016)
#255Earlier quoted context omitted.
But the point is that I do know what that will print on my computer(s), with my compiler(s), on my architecture(s). "I don't know" is too generic a statement.
Even on a given CPU with a given compiler you usually do not know until you've tried. This is an article about the C language and the starting point with all the examples is that you do not know for a fact what the result will be.
Re: So you think you know C? (2016)
#256Earlier quoted context omitted.
To me "I don't know" is a very apt choice. It makes the point clear that indeed reading the code does not allow you to know the result, which is quite a pitfall. In your comment you are jumping from "I don't know", which is the first step, to wanting to explain why.
There were multiple questions where I would have answered "It's undefined" or "It's implementation defined", but those weren't options. It's not that I don't know the answer; I know the answer ("it's implementation defined according to the spec, but on essentially every relevant platform, the result will be X"), but the "it's implementation defined" part of my answer isn't an option, so the only possible answer becom…
Re: So you think you know C? (2016)
#257But a code based on several standards, not only on C standard. For example we know, that basic source character sets should contain space (C11 5.2.1), we know that character constants has type "int" and that character constants represent value equal to the code of a symbol (C11 5.4.4). We know used source character set and we know code of the space character. We can configure specific source character set on the POSI…
Re: So you think you know C? (2016)
#258C, for all it's simplicity, is a relatively complex language.
Re: So you think you know C? (2016)
#259Re: So you think you know C? (2016)
#260But a code based on several standards, not only on C standard. For example we know, that basic source character sets should contain space (C11 5.2.1), we know that character constants has type "int" and that character constants represent value equal to the code of a symbol (C11 5.4.4). We know used source character set and we know code of the space character. We can configure specific source character set on the POSI…
I don't know if POSIX specifies CHAR_MAX, but on most systems, storing the value into a char will change the value, making it everything but 416: https://tio.run/##S0oszvifnFiiYFeSWlyil6xgY@Pq7/Y/M69EITcxM0...