https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123960

--- Comment #2 from Szymon Tarnowski <sz.tarnowski at gmail dot com> ---
Please accept my apologies. I tried to play more with this example and now I
discovered that I had made one step to much into simplification removing one
line with initialization of *ptr. Correct example which pass "-Wall --pedantic"
is:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char *memory, *ptr, var;
    memory = malloc(10);
    printf("%p allocated\n", memory);
    memory[0] = 42;
    memory[1] = 1;
    memory++;
    printf("%p incremented\n", memory);
    ptr = memory;
    ptr = memory + -((unsigned int)*ptr); //results with segmentation fault
when
//    ptr = memory -((unsigned int)*ptr); //works fine
    printf("%p after magic\n", ptr);
    var = *ptr;
    printf("read from pointer %d\n", var);
    return 0;
}

Reply via email to