delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/01/13:47:44

From: "George Kinney" <goober AT mail DOT net>
Subject: Re: struct in DJGPP
Newsgroups: comp.os.msdos.djgpp
References: <340A0B24 DOT 55B6E7F7 AT osu DOT edu>
Organization: The Unknown Programmers
Message-ID: <01bcb687$149858e0$f18033cf@markov>
NNTP-Posting-Host: 207.51.128.241
Date: 1 Sep 97 03:17:48 GMT
Lines: 50
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Mark Augustyn <augustyn DOT 3 AT osu DOT edu> wrote in article
<340A0B24 DOT 55B6E7F7 AT osu DOT edu>...
> I hate to ask a dumb question but is this the appropriate way to declare
> a struct:
> 
> struct cell {
>  int terrain;
>  BITMAP *tile;
> };
> 
> It seems simple enough, however, I get the following error when I
> declare a variable to be of type cell:
> Line 16:
>     cell map;
> 

I am assuming you are compiling this as C, not C++.
In this case, you need to specify that cell is a struct:
	struct cell map;

Otherwise the compiler has no way to know what 'cell' is.
You could also use a typedef as below:

typedef struct {
	int terrain;
	BITMAP *tile;
} cell;

cell map;

but in my opinion, it is a wiser idea to use the first method.
This way, you will always know that map is in fact a struct,
and not a typedef'd union or simple type. Which can help avoid many
problems when a project gets large, or you've been away from it for
a long time. (typos are the #1 bug producers, right before 
uninitialized pointers IMO).

> 
> What am I missing?  Do I need to include something to use structs and
> classes?

structs and classes are similar, but they are not the same thing.
Just remember to call a struct a struct, and you should be fine.

Good luck.

--------------------
George Kinney
gkinney (AT) usa (DOT) net

- Raw text -


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