delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/01/05:34:33

From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: struct in DJGPP
Date: Sun, 31 Aug 1997 21:02:38 -0400
Organization: Cornell University http://www.cornell.edu
Lines: 49
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <340A142D.BC725B20@cornell.edu>
References: <340A0B24 DOT 55B6E7F7 AT osu DOT edu>
Reply-To: asu1 AT cornell DOT edu
NNTP-Posting-Host: cu-dialup-0027.cit.cornell.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Mark Augustyn wrote:

> 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;
>
> test4.c:16: `cell' undeclared (first use this function)
>
> If I substitute class for struct I get the following as well:
> test4.c:7: parse error before `cell'
> test4.c:7: syntax error before `{'
> test4.c:10: parse error before `}'
>

oddly enough C is not C++. even stranger than that is the fact that gcc
assumes files with extension .c contain C source. in C, you need to say:

struct cell map;

to declare a variable of type struct cell. of course, you can define your
struct and a new data type:

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

then you can use the declaration:

cell map;

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

if you accidentally gave your file a .c extension, change the extansion to
.cc. if you are trying to write C, you will need to stay within the
language.

  -- Sinan

- Raw text -


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