Message-Id: Comments: Authenticated sender is From: "Salvador Eduardo Tropea (SET)" Organization: INTI To: nikki AT kki DOT net DOT pl (Inquisitor Nikodemus), djgpp AT delorie DOT com Date: Wed, 29 Jul 1998 11:47:25 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: GCC and pointers : QUESTION In-reply-to: <35bf1ff4.1246159@news.icm.edu.pl> Precedence: bulk nikki AT kki DOT net DOT pl (Inquisitor Nikodemus) 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 ? Yes, in fact C pointer arithmetic is like you say. Why? because the following are equivalent: a[1] and *(a+1) That's true even if a is an structure. If you really want to make byte adjustements with pointers cast the pointers to char: long *a; .... a=(long *)((char *)a+1); This will increase a in 1, of course normally "a" won't point to a valid value. SET ------------------------------------ 0 -------------------------------- Visit my home page: http://set-soft.home.ml.org/ or http://www.geocities.com/SiliconValley/Vista/6552/ Salvador Eduardo Tropea (SET). (Electronics Engineer) Alternative e-mail: set-soft AT usa DOT net set AT computer DOT org ICQ: 2951574 Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA TE: +(541) 759 0013