Skip to content

Commit 1fb655c

Browse files
authored
Rollup merge of rust-lang#154647 - folkertdev:avr-c_double-f32, r=tgross35
change `c_double` to `f32` on `avr` targets Extracted from rust-lang#152980. That version also makes this change for `msp430` but that is actually incorrect based on https://www.ti.com/lit/ug/slau132r/slau132r.pdf table 5-1 that specifies `double` as `f64`. r? tgross35 cc @Patryk27 @workingjubilee
2 parents 6bbf210 + dc9836e commit 1fb655c

2 files changed

Lines changed: 25 additions & 7 deletions

File tree

library/core/src/ffi/c_double.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Equivalent to C's `double` type.
22

3-
This type will almost always be [`f64`], which is guaranteed to be an [IEEE 754 double-precision float] in Rust. That said, the standard technically only guarantees that it be a floating-point number with at least the precision of a [`float`], and it may be `f32` or something entirely different from the IEEE-754 standard.
3+
This type will almost always be [`f64`], which is guaranteed to be an [IEEE 754 double-precision float] in Rust. That said, the standard technically only guarantees that it be a floating-point number with at least the precision of a [`float`]; some 16-bit systems use [`f32`], for example. Esoteric systems could use something entirely different from the IEEE-754 standard.
44

55
[IEEE 754 double-precision float]: https://en.wikipedia.org/wiki/IEEE_754
66
[`float`]: c_float

library/core/src/ffi/primitives.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,27 @@ macro_rules! type_alias {
1515
}
1616
}
1717

18-
type_alias! { "c_char.md", c_char = c_char_definition::c_char; #[doc(cfg(all()))] }
18+
// `#[doc(cfg(true))]` is used to prevent rustdoc from displaying a "Available on ..." box.
19+
// The implementation of these constants is target-specific, but every target does define them.
20+
21+
type_alias! { "c_char.md", c_char = c_char_definition::c_char; #[doc(cfg(true))] }
1922

2023
type_alias! { "c_schar.md", c_schar = i8; }
2124
type_alias! { "c_uchar.md", c_uchar = u8; }
2225
type_alias! { "c_short.md", c_short = i16; }
2326
type_alias! { "c_ushort.md", c_ushort = u16; }
2427

25-
type_alias! { "c_int.md", c_int = c_int_definition::c_int; #[doc(cfg(all()))] }
26-
type_alias! { "c_uint.md", c_uint = c_int_definition::c_uint; #[doc(cfg(all()))] }
28+
type_alias! { "c_int.md", c_int = c_int_definition::c_int; #[doc(cfg(true))] }
29+
type_alias! { "c_uint.md", c_uint = c_int_definition::c_uint; #[doc(cfg(true))] }
2730

28-
type_alias! { "c_long.md", c_long = c_long_definition::c_long; #[doc(cfg(all()))] }
29-
type_alias! { "c_ulong.md", c_ulong = c_long_definition::c_ulong; #[doc(cfg(all()))] }
31+
type_alias! { "c_long.md", c_long = c_long_definition::c_long; #[doc(cfg(true))] }
32+
type_alias! { "c_ulong.md", c_ulong = c_long_definition::c_ulong; #[doc(cfg(true))] }
3033

3134
type_alias! { "c_longlong.md", c_longlong = i64; }
3235
type_alias! { "c_ulonglong.md", c_ulonglong = u64; }
3336

3437
type_alias! { "c_float.md", c_float = f32; }
35-
type_alias! { "c_double.md", c_double = f64; }
38+
type_alias! { "c_double.md", c_double= c_double_definition::c_double; #[doc(cfg(true))] }
3639

3740
mod c_char_definition {
3841
crate::cfg_select! {
@@ -183,3 +186,18 @@ mod c_int_definition {
183186
}
184187
}
185188
}
189+
190+
mod c_double_definition {
191+
crate::cfg_select! {
192+
target_arch = "avr" => {
193+
// avr:
194+
// Per https://gcc.gnu.org/wiki/avr-gcc#Type_Layout. The table says `4,8` because
195+
// in C the width of `double` can be changed with the `-mdouble=32/64` setting. But
196+
// 32-bits is the default for the rust avr target.
197+
pub(super) type c_double = f32;
198+
}
199+
_ => {
200+
pub(super) type c_double = f64;
201+
}
202+
}
203+
}

0 commit comments

Comments
 (0)