Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
January 23, 2018, 09:07:02 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: #define scope  (Read 2145 times)
MarkReid
Full Member
***
Posts: 173


« on: October 16, 2009, 05:08:25 AM »

Just to clarify, if I use a #define statement at the top of my main program rather than in a header file, it still applies to all files I'm using in the program?

The only reason to place it in a header file would be to enable you to use that file in another program and avoid having to redefine the #define statement in the new program?

Does that sound right? The part that confused me is where the book mentions placing it in a header file making it so you can use it in more than one source file. Perhaps a definition of what a source file is would help clarify this for me.

Thanks
Logged
toby
Full Member
***
Posts: 104


« Reply #1 on: October 16, 2009, 07:58:02 AM »

I'm not 100% but I'm pretty sure that to use a #define it must be either in the source file you wish to use it or placed in a header file and the header file imported via something like #import "mymacros.h". The source files are the text files which have source code in them, the ones that end in .m in this case, the header files are the .h ones containing a class interface, function declarations, macros or similar.  Sometimes people use the header files to also declare variables which will be used as external variables.
« Last Edit: October 16, 2009, 08:01:02 AM by toby » Logged
MarkReid
Full Member
***
Posts: 173


« Reply #2 on: October 16, 2009, 08:06:58 AM »

That's a great explanation. Thank you.
Logged
toby
Full Member
***
Posts: 104


« Reply #3 on: October 16, 2009, 08:17:59 AM »

No worries, glad it made sense Smiley
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 classroomM.com. All rights reserved.