www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/17/00:55:16

From: j DOT aldrich6 AT genie DOT com
Message-Id: <199607170449.AA214278942@relay1.geis.com>
Date: Wed, 17 Jul 96 04:34:00 UTC 0000
To: lolo AT einev0 DOT einev DOT ch
Cc: djgpp AT delorie DOT com
Mime-Version: 1.0
Subject: Re: Syntax problem

Reply to message 2191609    from LOLO AT EINEV0 DOT E on 07/15/96 11:27AM


>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 ?

Without some specially-written extensions, what you're trying to do
is just not possible in C AFAIK.  The only truly reliable way to do
something like that is this:

typedef struct
{ long width;
  long height;
  char *pixels;
} toudoudou;

toudoudou.width=X;
toudoudou.height=Y;
toudoudou.pixels = (char *)malloc( sizeof(char) * width * height );

I saw another suggestion before mine; I honestly couldn't tell you how
likely that is to work, except that in C you can access a pointer as an
array and vice versa, and C doesn't do any range checking no matter
which method you use.

John

- Raw text -


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