[...]
As far as structure packing not being C, I would suggest that it is C
since #pragma without a STDC preprocessing token immediately following
it invokes implementation defined behavior according to the standard.
Thus anything the implementation wants to implement with a #pragma
directive is by definition standard C compliant. It may not be portable
but it is without question C and in compliance with the standard.
> [...]
C, or not-C?
int main(void) {
#pragma fortran
write (6,10)
10 format(14H Hello, world!)
#pragma c
return 0;
}
All right, that example is perhaps a little bit fanciful!
(Not completely implausible, though: consider all those postings
showing "C" sources with assembly languages embedded in them.)
My point is to offer the notion that #pragma moves the code out
of the noontime glare of the C Standard and somewhere into the
shadowy dusk -- or even, as above, into black midnight.
The semantics of #pragma are not (in my limited experience)
usually as drastic as my illustration. Still, even more "normal"
adjustments can raise issues with the language. The business of
struct packing, for example: Consider the notion of "compatible
type" as defined in the Standard, and ponder how you would need
to adjust it to accommodate a struct-packing #pragma. It is easy
to see that two "compatible" structs meeting all the Standard's
requirements can wind up being incompatible if one is packed and
the other is not. The #pragma thus makes the language not an
extended C, but a divergent C.
I've seen alignment-controlling #pragmas, too -- and they
can be even more deadly, IMHO. That's because lots of compilers
support a `#pragma align <number>' directive, but disagree over
the significance of the <number>: Does `#pragma align 16' specify
alignment to a 16-byte or a 65536-byte boundary? The promise that
the compiler will ignore a #pragma it doesn't recognize is of no
help in this case.
Even "harmless" #pragmas cast doubt on the code. If you
see `#pragma csect shared' you may guess that the linker is
being asked to put something in a "shared" area -- but shared
with whom, and by what kind of mechanism, and with what sort
of initialization, and ...? I opine that the answers to such
questions are essential to the proper operation of the program
(else the #pragma wouldn't be there), but that they almost
certainly change the semantics of the "shared" objects in ways
that are foreign to C.
#pragma transforms C code into "C, but ..." code. In the
context of the original poster's question
> I'm a beginner in C...May i like to know the difference between a
> #pragma and a #define....
.... I think "Don't Do That" is the correct answer, at least for
the time being.