delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/24/14:46:37

From: Vik Heyndrickx <Vik DOT Heyndrickx AT rug DOT ac DOT be>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Trouble with bools
Date: Fri, 24 Oct 1997 11:00:38 +0200
Organization: University of Ghent, Belgium
Lines: 36
Message-ID: <345063B6.5E29@rug.ac.be>
References: <199710220357 DOT NAA14199 AT rabble DOT uow DOT edu DOT au>
NNTP-Posting-Host: eduserv1.rug.ac.be
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Brett Porter wrote:
> 
> > Little know fact (well, not really) is that you can initalize
> > your array as follows..
> >
> > bool scrn[640][480] = {0};
> >
> Are you sure? I don't ever recall seeing this done.

I have. But I don't find it good practice. Either don't initialize your
elements, or initialize them all (except for character arrays that
receive a string as initializer).

> > You could initalize every variable this way as well (Even 2D, 3D... nD
> > arrays) by just putting a comma (,) after ever variable.
> > Ex.
> >
> > bool foo[2][3] = { 0, 1, 0, 1, 0, 1};
> >
> I'm almost certain this won't work, I think it should be {{0,1},{0,1},{0,1}}

This *will* work, but the compiler will issue a warning about it. What
you write is the most correct way.

> > only sets the first item of the array to 1 but the rest to 0.  As for how
...
> This is not really a standard as mar as I know. What is wrong with just
> memset(foo, 0, sizeof(foo)); ?

That you are assuming things about the internal representation of bool.
Which is certainly not standard!

-- 
+----------------+
| Vik Heyndrickx |
+----------------+

- Raw text -


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