From: "Graham Warren" Newsgroups: comp.os.msdos.djgpp Subject: Puzzling pointer behaviour Date: Sat, 13 Oct 2001 10:22:21 +0100 Organization: Tesco ISP Lines: 50 Message-ID: <9q90qi$lfl$1@barcode.btinternet.com> NNTP-Posting-Host: 212.140.70.28 X-Newsreader: Microsoft Outlook Express 4.72.3110.1 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hello, Thankyou to all who have helped me in the past. I've come across something slightly strange about byte pointers. Can anyone explain this. This small program demonstrates my query. When a byte pointer is made to point to an long int pointer, it actually points to the 8 least significant bits of the long int. Also, when this byte pointer is incremented it points 'left' of its original position. Why is this? /* POINTER.C */ #include int main (void) { int j; unsigned long int dword1 = 0; /* set a 32-bit int to zero */ unsigned long int *ptr_dword1 = &dword1; /* make a pointer to it */ unsigned char *ptr_byte1; ptr_byte1 = (unsigned char *) ptr_dword1; /* make ptr_byte1 point to the 32-bit int */ *ptr_byte1 = 255; /* set *ptr_byte1 to 255 */ /* optional lines */ ptr_byte1 += 2; *ptr_byte1 = 255; for (j = 0; j < 32; j++) { /* display the 32 bits of memory */ printf ("%i", (*ptr_dword1 & 0x80000000) ? 1 : 0); *ptr_dword1 = *ptr_dword1 << 1; } printf ("\n"); return 0; } /* end */ Thankyou, Graham Warren