cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/29/10:29:54

Date: Wed, 29 Jul 1998 17:21:32 +0300
From: Alexander Bokovoy <bokovoy AT bspu DOT ac DOT by>
Reply-To: Alexander Bokovoy <bokovoy AT bspu DOT ac DOT by>
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

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, <bokovoy AT bspu DOT unibel DOT by>
--=== The Soft Age coming soon ===--



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019