Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

youngplayer

macrumors member
Original poster
May 16, 2008
36
0
Shanghai,China
#import "MyController.h"

@implementation MyController



#pragma mark -
#pragma mark Startup and Shutdown

- (id) init
{
if (self = [super init])
{
_mailboxes = [[NSMutableArray alloc] init];
}
return self;
}

- (void) dealloc
{
[_mailboxes release];

[super dealloc];
}



#pragma mark -
#pragma mark Simple Accessors

- (NSMutableArray *) mailboxes
{
return _mailboxes;
}

- (void) setMailboxes: (NSArray *)newMailboxes
{
if (_mailboxes != newMailboxes)
{
[_mailboxes autorelease];
_mailboxes = [[NSMutableArray alloc] initWithArray: newMailboxes];
}
}


@end
------------------------------------------------------------------------------------------
As the above sample code shown, what do the #pragma sentences mean?
I have read the Programming in Objective-C, but it doesn't make me understood yet. Could someone explain more clearly? Thank you!


Paragraph in Programming in Objective-C:

The #pragma Directive
General Format:



#pragma text

This causes the preprocessor to perform some implementation-defined action. For example, under the pragma



#pragma loop_opt(on)

causes special loop optimization to be performed on a particular compiler. If this pragma is encountered by a compiler that doesn't recognize the loop_opt pragma, it is ignored.

The special keyword STDC is used after the #pragma for special meaning. Current supported switches that can follow a #pragma STDC are FP_CONTRACT, FENV_ACCESS, and CX_LIMITED_RANGE.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
#pragma mark directives show up in XCode in the menus for direct access to methods. They have no impact on the program at all.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
It means that these sentences are used as 'comment'?

what's the difference between '#pragma mark' and usual comment?
Why does the author write so?

Did you read what I wrote? At all? It tells XCode (or any other IDE that cares to check) to put an entry in it's drop-down menu for fast access to method definitions. That entry acts as a grouping or similar.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
I didn't realise there were others apart from Pragma Mark that's interesting.

There are lots. They are compiler (or pre-processor) specific pragmatic information.

You can get info on the GCC ones here

Unrecognised pragmas like mark will be ignored by the compiler so can safely be used for other purposes, such as layout hints for IDEs
 

youngplayer

macrumors member
Original poster
May 16, 2008
36
0
Shanghai,China
There are lots. They are compiler (or pre-processor) specific pragmatic information.

You can get info on the GCC ones here

Unrecognised pragmas like mark will be ignored by the compiler so can safely be used for other purposes, such as layout hints for IDEs

Thank you! Friend! It sounds wonderful of the usage of '#pragma mark'. I'll try when my Mac machine arrives.

BTW:where can I get more "#pragma" info for XCode?
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
Seriously, why don't you just type "pragma mark" into the Google box in Safari?

And seriously, why don't I check whether I am replying to a post from May 2008? :-(
 

Detrius

macrumors 68000
Sep 10, 2008
1,623
19
Apex, NC
Seriously, why don't you just type "pragma mark" into the Google box in Safari?

And seriously, why don't I check whether I am replying to a post from May 2008? :-(

May 2008? Ha!

For anyone curious, OpenMP is done almost entirely through pragmas. This way, compilers that don't know what to do with OpenMP can easily leave it out without all of the "ifdef" madness.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.