TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Robin Sheppard
from: Darin McBride
date: 1999-01-22 23:07:04
subject: Array Problem

DM> Nope - you didn't make ANY initialization effort.  Changing it to:

 DM> char *whee[10] = {NULL};

 DM> will initialize ALL of them to NULL (the first because of explicit
 DM> initialization, the rest because of implicit NULL initialization).
 RS>  
 RS>    Slick.  I take it this works with structs as well?  Some image 

With _arrays_ *AND* _structs_.

However, as Tom pointed out, and I kept meaning to, your "char*
whee[10];" *would* initialize to all zero *if* it were either global
*or* static, i.e., it had lifetime-of-program lifespan.  i.e.:

static char* whee[10]; /* all NULL pointers! */

 RS>    routines I'm working at will probably end up using a struct that 
 RS>    contains the dimensions of an image, and a pointer to the image 
 RS>    data.  I'd like to be able to set the dimensions to 0, and the 
 RS>    pointer to NULL, without having to explicitly initialize each 
 RS>    element of a struct array.

 RS>      struct image
 RS>      {
 RS>         short xsize;
 RS>         short ysize;
 RS>         char _far *data;
 RS>      }
 RS>      
 RS>      struct image sprites[16] = {0,0,NULL};
 RS>      
 RS>    This would do what I'm hoping?

Um, yeah, but it's kinda funny-lookin'.  :-)

A number of things here...

1. a struct can be partially initialized.  Often I'd do "struct image
sprite = {0};" to initialize the entire sprite to zero.

2. when initializing arrays of structs, I usually like to be somewhat more
explicit of what I'm initializing...

    struct foo bar[] = { /* usually done when I have all data up front */
        { 0, 1, 2, 3 },  /* bar[0] */
        { 4, 5, 6, 2 },  /* bar[1] */
           /*   ... etc ...   */
    };

In your case, it'd be 'struct image sprites[16] = { {0, 0, NULL } };'  It
obviously doesn't make any difference to the compiler... :-)

3. Sprites likely will have a lifespan of lifetime-of-program, so make it
static, and don't initialize.  They'll all be zero.  :-)

 RS>    Unfortunately, I have no internet access (well, I've got an email 
 RS>    address, but no realtime access), so grabbing it from a web or ftp 
 RS>    site is out of the question, unless I do it at a friend's place.

There are programs that convert ftp to email... you just need a really big
in box... :-)

 RS>    What kind of system requirements does it have?  I've got a 386/40 
 RS>    here with 8 megs of RAM, one 100-meg HD, and two 50-meg HDs.  Only 
 RS>    two of the three drives can be hooked up at a time, though, and my 
 RS>    100-megger is chronically hovering near the full point.

Um, prolly more than that.  Time for an upgrade... to a 500 meg HD.  :-)


---
* Origin: Tanktalus' Tower BBS (1:250/102)
SEEN-BY: 396/1 632/0 371 633/260 262 267 270 371 634/397 635/506 728 639/252
SEEN-BY: 670/218
@PATH: 250/102 201 99 396/1 633/260 635/506 728 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.