Professional Web Applications Themes

Is there any gcc option to turn off the alignment? - UNIX Programming

Jun S. Kang <com> wrote:                You can cast as much as you want but it won't allow you to do unaligned accesses on some architectures - it just allows you to cirvent all measures the system takes on your behalve to avoid unaligned accesses. You simply can't access memory at non-properly aligned addresses when doing multi-byte accesses on some machines (for example, if you want to read a 4-byte value it only can be done from addresses that are multiples of 4), Sparc being one of them. They don't have the hardware to ...

  1. #1

    Default Re: Is there any gcc option to turn off the alignment?

    Jun S. Kang <com> wrote: 
     
     
     
     
     
     
     

    You can cast as much as you want but it won't allow you to do unaligned
    accesses on some architectures - it just allows you to cirvent all
    measures the system takes on your behalve to avoid unaligned accesses.

    You simply can't access memory at non-properly aligned addresses when
    doing multi-byte accesses on some machines (for example, if you want to
    read a 4-byte value it only can be done from addresses that are multiples
    of 4), Sparc being one of them. They don't have the hardware to do that.
    If you need an int that starts at an odd address you have to read all
    bytes of the int in single bytes and then assemble the value from that
    bytes.

    The simplest way to get the above code to work portably I guess is

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    char data[] = { /* A random packet. */
    "\x01\x01\x01\x01\x01\x01"
    };

    int main (int argc, char *argv[])
    {
    int x;

    printf("[address of data][%x]\n", data);
    memcpy( &x, data, sizeof x );
    printf("[value of (int)*data][%x]\n", x );
    printf("[address of data + 1][%x]\n", (data + 1));
    memcpy( &x, data + 1, sizeof x );
    printf("[value of (int)*(data+1)][%x]\n", x );
    return 1;
    }
    Regards, Jens
    --
    \ Jens Thoms Toerring ___ fu-berlin.de
    \__________________________ http://www.physik.fu-berlin.de/~toerring
    Jens.Toerring@physik.fu-berlin.de Guest

  2. #2

    Default Re: Is there any gcc option to turn off the alignment?

    fu-berlin.de writes:
     

    It's probably faster to read two aligned ints and do some shifting.

    --
    Måns Rullgård
    se
    Måns Guest

  3. #3

    Default Re: Is there any gcc option to turn off the alignment?

    On Fri, 13 Feb 2004 04:04:27 +0100, se (Måns Rullgård) wrote:
     
    >
    >Think again and try to find a way that doesn't need unaligned
    >accesses. They can be hideously slow.[/ref]

    Yes, those bus errors generally abort the program, making it *very*
    slow ;-)

    --
    Al Balmer
    Balmer Consulting
    net
    Alan Guest

  4. #4

    Default Re: Is there any gcc option to turn off the alignment?

    Alan Balmer <net> writes:
     
    >>
    >>Think again and try to find a way that doesn't need unaligned
    >>accesses. They can be hideously slow.[/ref]
    >
    > Yes, those bus errors generally abort the program, making it *very*
    > slow ;-)[/ref]

    If the compiler can be persuaded into generating code for accessing
    unaligned values the program will run quite well, but slower.
    Furthermore, on Alpha machines the OS normally emulates unaligned
    accesses, so programs will still run without bus errors. On Sun SPARC
    the default is usually a SIGBUS.

    --
    Måns Rullgård
    se
    Måns Guest

Similar Threads

  1. No option in Acrobat 8 Pro to turn off Color Management
    By Paulette_Marzahl@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 1
    Last Post: October 10th, 02:13 PM
  2. Alignment
    By K_2_J in forum Macromedia Dynamic HTML
    Replies: 2
    Last Post: September 13th, 07:01 PM
  3. Replies: 0
    Last Post: June 16th, 02:04 PM
  4. Center Text alignment option
    By exingo@adobeforums.com in forum Adobe Photoshop Mac CS, CS2 & CS3
    Replies: 6
    Last Post: February 26th, 11:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139