Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Please help with structures!

Please help with structures!
Thread Tools
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Feb 10, 2001, 08:19 AM
 
I'm programming in Objective C. This is in one of my header files that I made:

#ifndef windowVariables
#define windowVariables
unsigned int windowNumber = 0;

typedef struct
{
GameWindow *window;
BOOL shouldClose;
}saveInfo;

typedef struct
{
GameWindow *window;
void *next;
}windowListNode;
#endif

Later in my program I use malloc to make come windowListNodes. But when I try to make a saveInfo thing, first here is the code that I used:

saveInfo *info;
info = (saveInfo *)malloc(sizeof(saveInfo));
info->window = window;
info->shouldClose = shouldClose;

Now here is the error that I get when i try to compile it:

GameController.m: In function `-[GameController saveAs:shouldClose:]':
GameController.m:78: parse error before `*'
GameController.m:79: `info' undeclared (first use in this function)
GameController.m:79: (Each undeclared identifier is reported only once
GameController.m:79: for each function it appears in.)

The * that it is referring to is in the line saveInfo *info; What is my problem? I can't seem to figure this out and it looks like it should be so simple.
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Feb 10, 2001, 01:53 PM
 
Hmmm... Are you declaring saveInfo the first thing in the block of code which it's in? If not, it'll generate that error like:

void function()
{
wee();
PXNumber *foo;
}

v |m|PXController.m (1 Error)
/_\ parse error before `*'

(like my ASCII representation of PB? :-)


If it's an int rather than a structure, it'll make a different error, but the idea's the same.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Dalgo  (op)
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Feb 10, 2001, 04:51 PM
 
Ok, I figured out what the problem was. I can't believe that I missed it. Since I didn't put in the entire method where I called SaveInfo *info; you couldn't see it. The problem was that SaveInfo *info; wasn't at the beginning of the method. I forgot that Objective C requires you to define all of your local variables at the beginning of the method. I had something like x= 4; before SaveInfo *info; so the compiler didn't like that. This is what I get for taking a class in C++ the same time that I'm teaching myself Objective C. I spent so long trying to figure out what the problem was and it was so simple. It's always the simple things that I get stuck on.The long, subtle mistakes I catch right away.
     
Forum Regular
Join Date: Feb 2001
Location: Portland, OR, USA
Status: Offline
Reply With Quote
Feb 11, 2001, 03:43 PM
 
Just a clarification. It isn't just at the beginning of methods, you can also declare variables at the beginnings of blocks like parallax mentioned. (Anywhere after a {, basically.)

     
Dalgo  (op)
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Feb 11, 2001, 04:30 PM
 
I never knew that you could declare a variable at the beginning of a block but it makes sense. Thanks.
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Feb 11, 2001, 05:54 PM
 
Yup, like:

for (i=0; i < 10; i++)
{
int *i;
...
}
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:20 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2