Subject: Re: B20: typedef bug?
From: [email-masked] (Fergus Henderson)

20 Jan 1999 18:05:21 -0800
Message-ID: <[email-masked]>
References: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
To: exe <[email-masked]>
Cc: [email-masked]

This has nothing to do with Cygwin.
Please ask such questions (and direct any follow-ups)
to the newsgroup comp.lang.c++.moderated.

On 02-Apr-1995, exe <[email-masked]> wrote:
> typedef char bmp_t[480][640];
> 
> void main() {
>   bmp_t*bmp=new bmp_t;
> }
> 
> results in...
> 
> test.cc: In function `int main(...)':
> test.cc:4: initialization to `char (*)[480][640]' from `char (*)[640]'
> 
> This occures in 3 different compilers (including non gnu-cpp), so mabey typedef was not intended to be used this way.
> It does appear to be a bogus error though.

You can argue about the merits of the language design, but
the compiler is correctly following the ISO C++ standard.
When you allocate an array using `new', it returns a pointer to
the first element.  This is true whether or not you use a typedef.

> the only good workaround I found is to create a macro that typecasts
> another type

A simpler alternative is

	bmp_t *bmp = new bmp_t[1];

However, you need to remember to deallocate it using

	delete [] bmp;

rather than just

	delete dmp;

Another alternative is to wrap the array inside a struct.

-- 
Fergus Henderson <[email-masked]>  |  "Binaries may die
WWW: <http://www.cs.mu.oz.au/~fjh>  |   but source code lives forever"
PGP: finger [email-masked]        |     -- leaked Microsoft memo.
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".