Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#pragma objective-c: can you have more than just 'mark'?

I am familiar with #pragma mark objective-c / xcode / ios development and that it is useful for finding sections of code.

However, I am wondering if there are other keywords other than 'mark'. Like, can you do #pragma somethingelse? Thanks in advance!

like image 506
Nathan Fraenkel Avatar asked Jun 13 '13 14:06

Nathan Fraenkel


1 Answers

First, some examples:

  1. You can control diagnostics:

    http://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas

  2. And from the same link:

    • clang supports the Microsoft "#pragma pack" feature for controlling record layout. GCC also contains support for this feature, however where MSVC and GCC are incompatible clang follows the MSVC definition.

    • clang supports the Microsoft #pragma comment(lib, "foo.lib") feature for automatically linking against the specified library. Currently this feature only works with the Visual C++ linker.

    • clang supports the Microsoft #pragma comment(linker, "/flag:foo") feature for adding linker flags to COFF object files. The user is responsible for ensuring that the linker understands the flags.

    The second and third from that list won't apply to your iOS code, though.

  3. Wikipedia [link] says that clang supports #pragma once, too.

And finally, here's a link to the clang API documentation for the pragma handling code. You can browse from there to see everything else. In particular, TokenKinds.def describes all the accepted tokens, so presumably it's complete:

#pragma unused
#pragma GCC visibility [push/pop]
#pragma pack [value/show/push/pop/etc/etc/etc]
#pragma clang __debug parser_crash
#pragma clang __debug captured
#pragma ms_struct [on/off]
#pragma align [native/natural/mac68k/power/reset]
#pragma weak [identifier]
#pragma weak [identifier = identifier] // alias
#pragma redefine_extname [identifier identifier]
#pragma STDC FP_CONTRACT
#pragma OPENCL EXTENSION
#pragma omp [...]
#pragma detect_mismatch
#pragma comment

The parsing code, found in ParsePragma.cpp, seems to indicate that not all of them are implemented, even if the front-end accepts them, though.

like image 111
Carl Norum Avatar answered Nov 15 '22 13:11

Carl Norum