Does this have anything to do with endian-ness?

Posted by eSKay on Stack Overflow See other posts from Stack Overflow or by eSKay
Published on 2010-05-15T05:21:31Z Indexed on 2010/05/15 5:34 UTC
Read the original article Hit count: 201

Filed under:
|
|
|

This piece of code:

#include<stdio.h>

void hello() { printf("hello\n"); }
void bye()   { printf("bye\n");   }

int main() {
    printf("%p\n", hello); 
    printf("%p\n", bye);
    return 0;
}

output on my machine:

0x80483f4
0x8048408

[second address is bigger in value]

on Codepad

0x8048541
0x8048511

[second address is smaller in value]

Does this have anything to do with endian-ness of the machines? If not,

  • Why the difference in the ordering of the addresses?

  • Also, Why the difference in the difference?

    0x8048541 - 0x8048511 = 0x30

    0x8048408 - 0x80483f4 = 0x14


Btw, I just checked. This code (taken from here) says that both the machines are Little-Endian

#include<stdio.h>

int main() {    
    int num = 1; 
    if(*(char *)&num == 1)
        printf("Little-Endian\n");
    else    
        printf("Big-Endian\n");

    return 0;       
}

© Stack Overflow or respective owner

Related posts about c

    Related posts about c++