| ... | ... | @@ -38,4 +38,23 @@ How to do it well |
|
|
|
|
|
|
|
### Conditional compilation
|
|
|
|
|
|
|
|
"Conditional compilation" in short is what its name suggests: compile depending on a condition. There are two ways to do this:
|
|
|
|
- Include <stdlib.h> (this is important!) and use `getenv()`. For example:
|
|
|
|
|
|
|
|
```
|
|
|
|
if (getenv("INPUT")) {
|
|
|
|
freopen(getenv("INPUT"), "r", stdin);
|
|
|
|
freopen(getenv("OUTPUT"), "w", stdout);
|
|
|
|
} // if
|
|
|
|
```
|
|
|
|
- You can also use compiler guards. You may have seen this before in header guards in the form of `#ifndef PATH_TO_FILE`. You can read more about it [here](https://msdn.microsoft.com/en-us/library/ew2hz0yd.aspx). On Mac OS, the operating system macro is `__APPLE__`
|
|
|
|
|
|
|
|
```
|
|
|
|
#ifdef __APPLE__
|
|
|
|
freopen(“inputFilename.txt”, “r”, stdin);
|
|
|
|
freopen(“outputFilename.txt”, “w”, stdout);
|
|
|
|
#endif
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Using environment variables |
|
|
\ No newline at end of file |