Date: Wed, 29 Jul 1998 17:21:32 +0300 From: Alexander Bokovoy Reply-To: Alexander Bokovoy Organization: BSPU named after Maxim Tank Message-ID: <5723.980729@bspu.unibel.by> To: djgpp AT delorie DOT com Subject: Re: GCC and pointers : QUESTION References: <35bf1ff4 DOT 1246159 AT news DOT icm DOT edu DOT pl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk Hi, All! 29.07.98, nikki AT kki DOT net DOT p wrote: > During writing a function I noticed that operations - such as addition > or substraction - on pointers of different types than char didn't > behave as I expected them to. Eg. adding 2 to the the pointer : > short *pointer_to_short ; > resulted in 4 byte offset,not 2 byte. Same for ints etc. > So the question is : is it really a fact,that gcc's pointer math > depends on type rather than raw bytes ? It is not an gcc feature or specific behaviour, it is standard C behaviour. When you have a variable foo: char *foo; then foo++ points to the next byte, ((int*)foo)++ points to the next int (+4 bytes in 32-bit program), ((double*)foo)++ points to the next double (+8 bytes I think). Regards, Alexander Bokovoy, --=== The Soft Age coming soon ===--