delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/15/23:41:52

Message-Id: <s1ebb693.080@MAIL.TAIT.CO.NZ>
Date: Tue, 16 Jul 1996 15:34:18 +1200
From: Bill Currie <bill_currie AT MAIL DOT TAIT DOT CO DOT NZ>
To: lolo AT einev0 DOT einev DOT ch
Cc: djgpp AT delorie DOT com
Subject: Re: Syntax problem

On 16/7/96  3:27 am, lolo <lolo AT einev0 DOT einev DOT ch> did thus say >>>
> Hello there.
> 
> I'm coding a texture viewer for quake and in The Unofficials Quake Specs
> I have this structure :
> 
> typedef struct
> { long width;
>   long height;
>   char pixels[width*height];
> } toudoudou;
> 
> but the use of the variables width and height for char pixels[]
> don't work with DJGPP.
> Is it because the 2 variables and pixels[] are in the same structure
> definition ?
> How to do that ?
> 
> Thanks

You can't actually do that in gcc what you do instead is:

typedef struct
{ long width;
  long height;
  char pixels[0];/* gcc allows this */
} toudoudou;

and in your code use the width and height values to calulate the size of the
structure. eg:

toudoudou *p=malloc(sizeof(toudoudou)+width*height);

the zero length array is a gcc c extension (also available in c++) documented in
the c extensions in the info pages for gcc.

Hope this helps
Bill

- Raw text -


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