delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/02/06:38:50

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Type casting problems with gcc
Date: Sun, 2 Mar 1997 10:39:19 +0000
Organization: None
Distribution: world
Message-ID: <97O8JIAXjVGzEwwo@talula.demon.co.uk>
References: <5f9trv$e6t AT crl9 DOT crl DOT com>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 27
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Samuel McGrath writes:
>I'm using the Allegro graphics library right now, and I'm trying to 
>reference the w and h fields of the BITMAP structure like this:
>
>void* bmp = create_bitmap(320,200);
>int bitmapwidth = (BITMAP*)(bmp)->w;

Why do you need to declare this as a void pointer? If you declared:

        BITMAP *bmp = create_bitmap(320,200);
        int bitmapwidth = bmp->w;

it would be quite a bit simpler :-)

If you really do need the void pointer for some reason, the problem is 
that your brackets are in the wrong place. You're looking up bmp->w, 
and then casting that to a bitmap pointer, while you want to do the cast 
before referencing the structure member. Instead, try:

        ((BITMAP *)bmp)->w;



/*
 *  Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
 *  Beauty is a French phonetic corruption of a short cloth neck ornament.
 */

- Raw text -


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