public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* quick question
@ 2006-02-16 14:57 Jim Stapleton
  2006-02-16 15:23 ` John Love-Jensen
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Jim Stapleton @ 2006-02-16 14:57 UTC (permalink / raw)
  To: gcc-help

I remember reading that there are systems where they don't like basic
variables to be put on offsets that are not an integer multiple of the
variable size, up to variables the size of a system word.

example, if this applied to the 32 bit x86 architechture where a word
is defined as 4 bytes (I'm talking about the actual arch here, and not
the bastardized useage form 16bit ASM):
char [1 byte]: can be anywhere
short [2 bytes]: any 2N address, where N is an integer, and N > 0.
int/long [4 bytes]: any 4N address, where N is an integer, and N > 0
long long [8 bytes]: any 4N address, where N is an integer, and N > 0
(8 bytes > 1 word)


Now, this set of code works on the x86 platform, but I'm worried it
may not work on other platforms, am I correct in this worry?

#include <stdio.h>

=======================================================
int main()
{
  char test[] =  {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a};
  char *tptr = test;
  int *ptr;

  ptr = (int*)tptr;
  printf("tptr[0]: %x\n", *ptr);

  tptr++;
  ptr = (int*)tptr;
  printf("tptr[1]: %x\n", *ptr);

  tptr++;
  ptr = (int*)tptr;
  printf("tptr[2]: %x\n", *ptr);

  tptr++;
  ptr = (int*)tptr;
  printf("tptr[3]: %x\n", *ptr);

  return 0;
}
=======================================================

output (note: all my machines are 32 bit x86, so this output is
correct for them, on reasonable endian machines, the bytes in the
output would be reversed):
tptr[0]: 3020100
tptr[1]: 4030201
tptr[2]: 5040302
tptr[3]: 6050403



Thanks
-Jim

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2006-02-16 20:20 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-16 14:57 quick question Jim Stapleton
2006-02-16 15:23 ` John Love-Jensen
2006-02-16 15:28 ` Perry Smith
     [not found]   ` <80f4f2b20602160737q5684d6c3l5df46c8a64fe47ad@mail.gmail.com>
2006-02-16 15:39     ` Jim Stapleton
2006-02-16 20:20       ` Ben Rudiak-Gould
     [not found]     ` <D94028E4-C732-4FB6-8C07-D38676404EEB@easesoftware.net>
2006-02-16 16:17       ` Jim Stapleton
2006-02-16 16:22         ` random
2006-02-16 16:37           ` Perry Smith
2006-02-16 15:35 ` Brian Dessent
2006-02-16 15:39   ` Jim Stapleton
2006-02-16 15:46     ` Brian Dessent
2006-02-16 15:56       ` Jim Stapleton
2006-02-16 15:49     ` Jim Stapleton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).