Bug Report

Steve Sun ss01@gte.com
Wed May 23 12:10:00 GMT 2001


Dear Sir, 

I was surprised by the result of this simple program compiling with gcc 
2.95 on Red Hat Linux 7.0.
Could you check whether is it a bug of gcc 2.95 (for Red Hat Linux 7.0)?

Sincerely, Stephen Sun 
#include <stdio.h>

main()
{
    char        *ptr, arr[4];
    int		id = 50724871;
		/* id: 00000011 00000110 00000000 00000111 */

    ptr = (char *) &id;		/* ptr points to leftmost bit of id */
    arr[0] = *(ptr);		/* arr[0] = left-most byte of id    */
    arr[1] = *(ptr + 1);	/* arr[1] = 2nd byte of id          */
    arr[2] = *(ptr + 2);	/* arr[2] = 3rd byte of id          */
    arr[3] = *(ptr + 3);	/* arr[3] = right-most byte of id   */

    printf("size of int = %d bytes.\n", sizeof(int));

    printf("arr[0] = %d, should be 3.\n", (int) arr[0]); 
    printf("arr[1] = %d, should be 6.\n", (int) arr[1]);
    printf("arr[2] = %d, should be 0.\n", (int) arr[2]);
    printf("arr[3] = %d, should be 7.\n", (int) arr[3]);	

    return 0;
}



More information about the Gcc-bugs mailing list