C/Macro Preprocessor/if def
Содержание
#define and #ifdef
<source lang="cpp"> //file1.h
- define USD 1
//file2.h
- define UKP 1
//file3
- include <stdio.h>
- include <file1.h>
- if !defined (USD) || !defined (UKP)
#error "RROR: NO_CURRENCY rate is specified."
- endif
main() {
int rs; rs = 10 * currency_rate; printf ("d\n", rs);
}
</source>
#define, #ifdef #else example
<source lang="cpp">
- include <stdio.h>
- define TED 10
int main(void) {
- ifdef TED
printf("Hi Ted\n");
- else
printf("Hi anyone\n");
- endif
- ifndef RALPH
printf("RALPH not defined\n");
- endif
return 0;
}
</source>
Simple #if/#else example
<source lang="cpp">
- include <stdio.h>
- define MAX 10
int main(void) {
- if MAX>99
printf("Compiled for array greater than 99.\n");
- else
printf("Compiled for small array.\n");
- endif
return 0;
}
</source>
Simple #if example
<source lang="cpp">
- include <stdio.h>
- define MAX 100
int main(void) {
- if MAX>99
printf("Compiled for array greater than 99.\n");
- endif
return 0;
}
</source>