Lefora Free Forum
login join
Loading
466 views

#pragma

Page 1
1–5
novice - member
27 posts

What does #pragma mean?

?
288 posts

A pragma is an instruction to the compiler to do something.  It's not part of your code (it's not an executable statement), you're speaking to the compiler.

For example, it's quite common for engineers to add warning messages in code like:

#pragma warning "TODO this code has not been tested in 64 bit mode"

The compiler will then generate a warning message in the output when you compile/build the code.

You can also use pragmas to disable warnings.  Some companies requires that all release builds generate no warnings.  You may not submit code that generates warning messages. Usually you can recode and avoid warnings - however sometimes you can not and the compiler always complains about something.  A pragma and comment to explain why the warning has been suppressed will usually get us back to no warnings.

The family of pragmas available depends on the implementation of the compiler.  pragmas can be used to control warnings, data structure packing, compilation modes and all sorts manner of things.

__________________
?
63 posts

You could also use the mark thing:
#pragma mark Accessors
-(void)setFoo:(int)obj;
-(int)foo;
#pragma mark Arithmetic
-(void)add:(int)x;
// ………

__________________
kompilesoft

come and see my website! it's real cool reviews
?
288 posts

Good point, kompilesoft.

Yes, the rules of the pragma are:  if the compiler doesn't recognize the pragma, he should ignore it!  So #pragma mark is probably not understood at all by GCC, however the text editor in XCode uses that to build little menus in a pull-down menu at the top of the editor window.

I do find #pragma mark very useful.  DevStudio on the other hand is able to do that automatically without any input from the user.  Maybe XCode4 will support this kind of thing.  We'll see.

__________________
?
63 posts

Very "pragma"-tic? :D

__________________
kompilesoft

come and see my website! it's real cool reviews
Page 1
1–5

Locked Topic


You must be a member to post in this forum

Join Now!