Log in

View Full Version : Pragma


Eclipse
10-02-2007, 13:27
So, I've seen the pre-processor command #pragma in several files and have heard people talking about it, but I haven't a clue what it does. Can anyone explain this to me? o_ô

Mike Betts
10-02-2007, 16:58
Try reading this (http://www.chiefdelphi.com/forums/showpost.php?p=454697&postcount=12).

Is your question answered?

Joe Ross
11-02-2007, 02:16
#PRAGMA is a compiler directive. It is a way to pass information to the compiler that is not standard ANSI C. Because of that, there isn't any standard. One compiler may have a #PRAGMA command that doesn't work with any other compiler.

The post the Mike linked to is one example of a #PRAGMA for the C18 compiler. Another example is in this thread: http://www.chiefdelphi.com/forums/showthread.php?t=51550 Another example, for one project using Borland C, I used #PRAGMA pack to tell the compiler to byte align a particular structure, instead of word aligning it like default. If I were to try to move that code to another compiler, I would have to find out how to byte align structures with that compiler.

You can find a full listing of all the #PRAGMA directives that the C18 compiler supports in the MPLAB C18 C Compiler User's Manual here: http://kevin.org/frc/C18_users_guide.pdf

You can do a lot of neat things with #PRAGMA, but it's also one of the easiest ways to write non-portable code (not a big deal for our use, but it is in industry).