delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/01/20:19:36

From: "Ole Laursen" <ole_laursen AT hardworking DOT dk>
Newsgroups: comp.os.msdos.djgpp
References: <37a49d74 AT news DOT ismi DOT net>
Subject: Re: BITMAP pointers w/ Allegro.
Lines: 39
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2314.1300
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
Message-ID: <0I2p3.31$l4.1288@news030.image.dk>
Date: Sun, 1 Aug 1999 23:07:34 +0200
NNTP-Posting-Host: 212.54.71.48
X-Complaints-To: news-abuse AT wol DOT dk
X-Trace: news030.image.dk 933541756 212.54.71.48 (Sun, 01 Aug 1999 23:09:16 MET DST)
NNTP-Posting-Date: Sun, 01 Aug 1999 23:09:16 MET DST
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

> main(void)
> {
>    BITMAP *bmp;
>    function(bmp);
> }
>
> function(BITMAP *bmp)
> {
>    bmp = create_bitmap(320, 240);
> }
>
> How do I pass the bitmap by reference so I can edit its value in
> sub-functions?

This will do, I think (warning: I haven't tested it, might have made a
mistake):

main(void)
{
  BITMAP *bmp;
  function(&bmp);      // passing address
}

function(BITMAP **bmp) // getting pointer to pointer to BITMAP
{
  *bmp = create_bitmap(320, 240); // first dereference, then assign
}

So you use a pointer to a BITMAP-pointer to refer to the address of the
BITMAP-pointer variable, thereby being able to change the variable. There
are other possibilities, too, e.g. if you had been using C++ you could have
used a reference with a '&'.


--
Ole Laursen - http://sunsite.auc.dk/olau/
Row, row, row your boat, gently down the streeaam (gee!)


- Raw text -


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