Code::Blocks Forums

User forums => Help => Topic started by: Greedy_Lemon on May 24, 2020, 10:40:52 pm

Title: Bug: Same code, same compiler (newest cygwin gcc) wrong result in Code::Blocks
Post by: Greedy_Lemon on May 24, 2020, 10:40:52 pm
Hey,

I am facing strange result after running in Code::Blocks the same code as in CLion (same compiler- newest cygwin gcc):
Code
#include <stdio.h>

int main(void)
{
    char n1[100] = "Ala";

    char *p;
    for(p= n1; p < n1 + 10; p++)
        printf("Address: %p,  c: %c  d: (%d)\n", p, *p, *p);

    return 0;
}

In Code::Blocks result is probably wrong, 1 image. Second one is from CLion, the same compiler used and the result is the proper one (tested with friends).


Any indeas or suggestions? Thank you in advance.


Title: Re: Bug: Same code, same compiler (newest cygwin gcc) wrong result in Code::Blocks
Post by: BlueHazzard on May 24, 2020, 10:48:15 pm
codeblocks is not a compiler, so anything different on runtime is not caused by codeblocks, but by the compiler/runtime

I see no error in both outputs, just different memory initializations during runtime...
Title: Re: Bug: Same code, same compiler (newest cygwin gcc) wrong result in Code::Blocks
Post by: huycan on May 24, 2020, 11:11:36 pm
Agreed. Nothing's wrong with the output. They're both correct. Just different memory location.
Title: Re: Bug: Same code, same compiler (newest cygwin gcc) wrong result in Code::Blocks
Post by: BlueHazzard on May 24, 2020, 11:26:50 pm
No, not only "location", but "initialization".
Location is hopefully always different on every run and on any system...
but also: unix systems (like cygwin is) seem to initialize memory with 0, at least if you make a debug build. Windows systems do not...
Title: Re: Bug: Same code, same compiler (newest cygwin gcc) wrong result in Code::Blocks
Post by: sodev on May 24, 2020, 11:52:58 pm
Accessing uninitialized memory is undefined behavior so by definition every result is correct :D
Title: Re: Bug: Same code, same compiler (newest cygwin gcc) wrong result in Code::Blocks
Post by: Greedy_Lemon on May 28, 2020, 01:30:36 am
Ok, I understand now. Thank you very much for help  :)