cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/29/15:42:53

From: "Martin Ambuhl" <mambuhl AT tiac DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: GCC and pointers : QUESTION
Date: Wed, 29 Jul 1998 15:31:25 -0400
Organization: Nocturnal Aviation
Lines: 33
Message-ID: <6pnt77$nhs@news-central.tiac.net>
References: <35bf1ff4 DOT 1246159 AT news DOT icm DOT edu DOT pl>
NNTP-Posting-Host: p5.tc2.newyo.ny.tiac.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Inquisitor Nikodemus wrote in message
<35bf1ff4 DOT 1246159 AT news DOT icm DOT edu DOT pl>...
|Hey!
|
|
|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 really a fact that all legal C implementation do pointer
arithmetic with regard to type.  That is why pointer arithmetic on void
* is undefined in standard C (gcc has a loophole here): there is no size
associated with void.

Since E1[E2] means the same thing as *(E1+(E2)), this in an inescapable
fact of life in C.

Your question is about C rather than about gcc.  If you have more
questions about C, the right newsgroup is news://comp.lang.c

Martin Ambuhl (mambuhl AT tiac DOT net)
/* Newsgroup posts also e-mailed */
|
|
|/greetz
|Nikki


- Raw text -


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