Better HN
topnewbestaskshowjobs
Log inSign up

kevin_clever

3 karma · joined Nov 4, 2017 (9y ago) · 2 submissions

Submissions

comment 9y ago · link · parent

So, it's a compiler specific reordering?

comment 9y ago · link · parent

I tried the example below, saved as `main.c`. It seems she automatically reorders the static mem. Can that behavior be disabled? Can someone please explain?

    #include<stdio.h>
    int main(int argc, char** argv)
    {
    	char *p;
	char c;
	int x;

        printf("char p  %p\n", &p);
        printf("char    %p, offset %i\n", &c, (int)((void*)&c-(void*)&p));
        printf("integer %p, offset %i\n", &x, (int)((void*)&x-(void*)&p));
        return 0;
    }
Output on `gcc main.c; ./a.out`

    char p  0x7ffc5107dff0
    char    0x7ffc5107dfeb, offset -5
    integer 0x7ffc5107dfec, offset -4