| delorie.com/archives/browse.cgi | search |
| X-Authentication-Warning: | delorie.com: mail set sender to djgpp-bounces using -f |
| From: | "Alex Vinokur" <alexvn AT foot DOT com> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Re: Trouble of using very large arrays |
| Date: | Fri, 23 Apr 2004 12:00:28 +0300 |
| Lines: | 50 |
| Message-ID: | <c6alve$9r230$1@ID-79865.news.uni-berlin.de> |
| References: | <c68d6j$g57$03$1 AT news DOT t-online DOT com> <c68e70$96gqq$1 AT ID-231750 DOT news DOT uni-berlin DOT de> <c68u9l$9fevb$1 AT ID-79865 DOT news DOT uni-berlin DOT de> <urih80l3b6om4kbblr8jthpjbm1i7cp6gc AT 4ax DOT com> |
| NNTP-Posting-Host: | 82.166.218.223 |
| X-Trace: | news.uni-berlin.de 1082710830 10324064 I 82.166.218.223 ([79865]) |
| X-Priority: | 3 |
| X-MSMail-Priority: | Normal |
| X-Newsreader: | Microsoft Outlook Express 6.00.2800.1106 |
| X-MimeOLE: | Produced By Microsoft MimeOLE V6.00.2800.1106 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
"Brian Inglis" <Brian DOT Inglis AT SystematicSw DOT Invalid> wrote in message news:urih80l3b6om4kbblr8jthpjbm1i7cp6gc AT 4ax DOT com...
> On Thu, 22 Apr 2004 20:10:08 +0300 in comp.os.msdos.djgpp, "Alex
> Vinokur" <alexvn AT big DOT foot DOT com> wrote:
>
> > a = (unsigned int*)malloc (rows * columns * sizeof (unsigned int));
>
> Nitpicks:
>
> -- avoid casting malloc results, as it is unnecessary to cast a void
> pointer to any other type of pointer, but the explicit cast will mask
> not declaring malloc or including stdlib.h, and also mask assignment
> to a non-pointer type;
I prefer to compile C-program with C++ compiler.
So, if foo.c contains
-----------------------------------------------------------
a = malloc (rows * columns * sizeof (unsigned int));
-----------------------------------------------------------
We have
$ gpp foo.c
error: invalid conversion from `void*' to `unsigned int*'
>
> -- avoid using types for sizes, in case someone later changes the
> assigned pointer type; use object sizes instead;
Good point! Thanks.
>
> this is cleaner and more maintainable:
>
------ With C-compiler ------
> a = malloc(rows * columns * sizeof *a);
------ With C++-compiler ------
a = (unsigned int*)malloc(rows * columns * sizeof *a);
>
[snip]
--
Alex Vinokur
mailto:alexvn AT connect DOT to
http://mathforum.org/library/view/10978.html
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |