muttaa wrote:
Hello all,
I'm a beginner in C...May i like to know the difference between a
#pragma and a #define....
Also,yet i'm unclear what a pragma is all about as i can find topics on
it only in high-standard books...
For a beginner, the difference is simple: #define is
something you use, but #pragma is something you avoid.
#define creates a macro. When the macro name appears
later on in the program, the text of the macro definition
replaces the name. (That's a loose description, not perfect
but good enough for all but language lawyers.) A macro is
a kind of shorthand; using the shorthand, you may be able
to write your program more briefly and more clearly.
#pragma tells the compiler to do something peculiar. It
may tell the compiler to allocate a variable on an 8192-byte
boundary, or to use a non-standard mechanism for calling a
function, or that some special action is to be taken before
main() is called, or ... With a very few exceptions, the
effect of a #pragma directive is entirely defined by the
particular compiler you happen to be using; switch to a
different compiler and the same #pragma in your source code
may have an entirely different effect. In other words, #pragma
ties your code to just one compiler, thus giving up nearly all
the portability C is famous for.
Use #define when it seems useful. When #pragma seems like
a good idea, you are probably hallucinating and should get some
bed rest.
--
Eric Sosman
es*****@acm-dot-org.invalid