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 > NSRect declaration...

NSRect declaration...
Thread Tools
Fresh-Faced Recruit
Join Date: Sep 2000
Status: Offline
Reply With Quote
Jul 5, 2001, 08:04 PM
 
As mentioned in anoter thread, I am overriding the drawRect function in a subclass of NSOpenGLView. I got it all working, and was trying to create a second NSRect, but the compiler was complaining about my declaration, which was just: NSRect aRect;

I could not figure out what was going on for the longest time. Finally, I just moved the declaration to the top of the function and, like magic, it worked. No problems whatsoever, and the only difference was moving it to the top of the function rather than towards the middle.

Now, as I said, everything is working. But I still don't understand why this was happening. Can someone fill me in on just what was going on? And why did moving the declaration fix the problem?

Thanks alot. I'm learning a ton here, and can't state how strongly I appreciate all the help.

Spencer
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jul 5, 2001, 09:44 PM
 
EVERYTHING's got to be at the top of a block of code (usually a function, but you _can_ declare variables within all braces, like ifs or fors; however, those go out of scope). Try that with an int or char in the middle. Chances are, you'll get a parse error.

Hope that helps,

-px
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Jul 6, 2001, 01:03 PM
 
This isn't just related to Cocoa, it happens in all of C. The C89 standard says that all declarations go at the top of a block, but the C99 standard allows inline declarations (as does C++). The only problem is that very few compilers support C99, Apple's GCC included.
     
   
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:44 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