www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/10/12/16:28:32

From: mert0407 AT sable DOT ox DOT ac DOT uk (George Foot)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Pointers
Date: 12 Oct 1996 19:13:40 GMT
Organization: Oxford University, England
Lines: 23
Message-ID: <53oql4$qg7@news.ox.ac.uk>
References: <53oa2v$kr4 AT miracle DOT cybernex DOT net>
NNTP-Posting-Host: sable.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

mrichman AT cybernex DOT net wrote:
: Is it safe to assume that all pointer variables take up the same
: number of bytes, or is that compiler dependent.

If you're writing really portable code, it's not safe to assume anything. 
If you make a #define at the start of your source, e.g.

#define POINTER_SIZE sizeof(*void)

then use this, e.g.

int *my_array[20];

for (int a=0;a<20;a++)
 printf("%d\n",*(my_array+a*POINTER_SIZE));

then when you compile on a different platform the multiplier will be 
correctly adjusted.

Of course, it's much simpler to write "my_array[a]", but I presume you 
don't want to do this for some reason.

George Foot

- Raw text -


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