Pragmatic directives: Difference between revisions

Content added Content deleted
(Added Kotlin)
(Added C implementation.)
Line 58: Line 58:
'''
'''


=={{header|C}}==
The C Preprocessor is well explained on the [https://gcc.gnu.org/onlinedocs/cpp/index.html#Top GNU] site. The pragma page is [https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html here].
<lang C>
/*Abhishek Ghosh, 7th October 2017*/

/*Almost every C program has the below line,
the #include preprocessor directive is used to
instruct the compiler which files to load before compiling the program.

All preprocessor commands begin with #
*/
#include<stdio.h>

/*The #define preprocessor directive is often used to create abbreviations for code segments*/
#define Hi printf("Hi There.");

/*It can be used, or misused, for rather innovative uses*/

#define start int main(){
#define end return 0;}

start

Hi

/*And here's the nice part, want your compiler to talk to you ?
Just use the #warning pragma if you are using a C99 compliant compiler
like GCC*/
#warning "Don't you have anything better to do ?"

#ifdef __unix__
#warning "What are you doing still working on Unix ?"
printf("\nThis is an Unix system.");
#elif _WIN32
#warning "You couldn't afford a 64 bit ?"
printf("\nThis is a 32 bit Windows system.");
#elif _WIN64
#warning "You couldn't afford an Apple ?"
printf("\nThis is a 64 bit Windows system.");
#endif

end

/*Enlightened ?*/
</lang>
On compilation and output, the compiler type is detected rather than the actual OS :
<pre>
C:\rosettaCode>gcc pragmatic.c
pragmatic.c:22:2: warning: #warning "Don't you have anything better to do ?"
pragmatic.c:28:2: warning: #warning "You couldn't afford a 64 bit ?"

C:\rosettaCode>a
Hi There.
This is a 32 bit Windows system.
</pre>
=={{header|Common Lisp}}==
=={{header|Common Lisp}}==