| |
| Posted by pascal111 in reply to kdevel | PermalinkReply |
|
pascal111
Posted in reply to kdevel
| On Thursday, 28 July 2022 at 13:06:03 UTC, kdevel wrote:
> On Thursday, 28 July 2022 at 12:25:05 UTC, pascal111 wrote:
> [...]
> ofix.c: In function 'fix':
ofix.c:7:3: warning: 'z' is used uninitialized [-Wuninitialized]
7 | y=modf(x,z);
| ^~~~~~~~~
ofix.c:5:12: note: 'z' was declared here
5 | double y,* z;
| ^
I would also like to complain about the double assignment to `y`.
"fix" function is the C version of BASIC standard one I made, it's the equivalent of "trunc" in D, but the code I programmed for "fix" was with TC++ , and it worked in DOS emulators with no problem,
"Code works" and "Code is correct" are two distinct categories. The compiler's warnings show that your code is not correct and not that it will necessarily not work. Incorrect code may work accidentally.
for that we are - guys of C - prefer C of other languages like Pascal, because C allow us to have working programs although they are not 100% correct, but something like Pascal is so hard and difficult in its compiling, it'll give us an error for even a so small expression, so we don't like the much complaints of compilers, and C is so forgiving language.
> As a (future) software developer you are required to not just produce code that "works" "with no problem" but also code that is correct. "Correct" here means that the code adheres to the specifications of the language.
Writing incorrect code is like "fixing" a "broken" fuse with tin foil.
> I have no idea how gcc will treat my code, but I think you are right that some other compilers will refuse such code, because VC++ 6 refused many of these functions codes I programmed with TC++ compiler.
The incorrectness of your C code does not depend on the compiler brand.
I have to change the compiler, not the code!
|