Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Where to include header files - relates to last question on variable scope



Chris Hanson wrote:

On Oct 31, 2004, at 7:10 AM, Ole Voss wrote:

This also means, that I have to include the header file wherever I need it?
That could mean that the same class has to be recompiled tens of times -
right?


You need to distinguish between the declaration and the definition.

The definition needs to be compiled only once. The declaration needs to appear prior to its use in any compilation unit that needs to make use of the information in it; that's what #include and #import do.

This is true for all of C, C++, and Objective-C and is fundamental to these languages' compilation model.

So what possibilities do I have to create global variables?


You create global variables in Objective-C in exactly same way that you create them in C. Declare your global variable in a header file as extern, and define it in a single implementation file.

-- Chris


Yes, that does sound feasible but I would still have to re-include this header file in every class that I use it in?

I'm just spoilt because I've been programming Perl for over five years now and that language just does everything for you ;-)

If I include my module once - it just stays available to all my other modules and I don't have to re-include it.

C is too far away to even remember...



Thank you,


Ole.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: Where to include header files - relates to last question on variable scope (From: Chris Hanson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.