Skip to content

Commit

Permalink
Clarify conditional compilation
Browse files Browse the repository at this point in the history
Introduction of `cfg` attribute and `cfg!` macro operators is
misleading. `cfg!` macro has nothing to do with conditional compilation,
but it can be used for run-time conditional checks. It is `cfg`
attribute that enables conditional compilation. Clarify the
responsibilities of the operators.
  • Loading branch information
gokhanettin committed Apr 23, 2020
1 parent c106d16 commit b44a1f3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/attribute/cfg.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# `cfg`

Conditional compilation is possible through two different operators:
Configuration conditional checks are possible through two different operators:

* the `cfg` attribute: `#[cfg(...)]` in attribute position
* the `cfg!` macro: `cfg!(...)` in boolean expressions

Both utilize identical argument syntax.
While the former enables conditional compilation, the latter allows for run-time
checks. Both utilize identical argument syntax.

```rust,editable
// This function only gets compiled if the target OS is linux
Expand All @@ -22,7 +23,7 @@ fn are_you_on_linux() {
fn main() {
are_you_on_linux();
println!("Are you sure?");
if cfg!(target_os = "linux") {
println!("Yes. It's definitely linux!");
Expand Down

0 comments on commit b44a1f3

Please sign in to comment.