delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/01/17:15:17

From: "Elias Pschernig" <f DOT x DOT gruber-museum-arnsdorf AT magnet DOT at>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: What's the idea with ALLEGRO.H's zero-size arrays?
Date: Mon, 1 Nov 1999 22:06:03 +0100
Organization: Telenor magnet GmbH
Message-ID: <7vkvbs$r9q$1@orudios.magnet.at>
References: <7vk0b0$92j$1 AT baker DOT cc DOT tut DOT fi>
NNTP-Posting-Host: 195.170.72.29
X-Trace: orudios.magnet.at 941490364 27962 195.170.72.29 (1 Nov 1999 21:06:04 GMT)
X-Complaints-To: abuse AT magnet DOT at
NNTP-Posting-Date: 1 Nov 1999 21:06:04 GMT
X-Newsreader: Microsoft Outlook Express 4.71.1712.3
X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3
Lines: 34
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

>Hi!
>
>I tried to compile my new program with '-pedantic' switch, but
>djgpp shows me following data....
>
>djgpp/include/allegro.h:948: warning: ANSI C++ forbids zero-size
array `line'
>djgpp/include/allegro.h:1498: warning: ANSI C++ forbids zero-size
array `dat'
>
>What's the idea with zero-size arrays?

They are used in structures with changeable size.
If you have

struct bitmap {
  int w,h...
  void *line[0]; // zero size array
};

,you can allocate a bitmap with x lines later with

a_bitmap=...malloc(sizeof(struct bitmap)+sizeof(void *)*x);

.Now the array has x elements really.

The idea is that you have only one call to malloc. Without the zero
size array, you'd have to store a pointer in the bitmap structure, and
do a second malloc to create the list of line pointers...


Elias Pschernig


- Raw text -


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