@@ -1308,6 +1308,9 @@ struct Cookie;
1308
1308
let c = [Cookie, Cookie, Cookie, Cookie];
1309
1309
~~~~
1310
1310
1311
+ The precise memory layout of a structure is not specified. One can specify a
1312
+ particular layout using the [ ` repr ` attribute] (
1313
+
1311
1314
By using the ` struct_inherit ` feature gate, structures may use single inheritance. A Structure may only
1312
1315
inherit from a single other structure, called the _ super-struct_ . The inheriting structure (sub-struct)
1313
1316
acts as if all fields in the super-struct were present in the sub-struct. Fields declared in a sub-struct
@@ -1941,6 +1944,23 @@ interpreted:
1941
1944
- ` linkage ` - on a static, this specifies the [ linkage
1942
1945
type] ( http://llvm.org/docs/LangRef.html#linkage-types ) .
1943
1946
1947
+ On ` enum ` s:
1948
+
1949
+ - ` repr ` - on C-like enums, this sets the underlying type used for
1950
+ representation. Takes one argument, which is the primitive
1951
+ type this enum should be represented for, or ` C ` , which specifies that it
1952
+ should be the default ` enum ` size of the C ABI for that platform. Note that
1953
+ enum representation in C is undefined, and this may be incorrect when the C
1954
+ code is compiled with certain flags.
1955
+
1956
+ On ` struct ` s:
1957
+
1958
+ - ` repr ` - specifies the representation to use for this struct. Takes a list
1959
+ of options. The currently accepted ones are ` C ` and ` packed ` , which may be
1960
+ combined. ` C ` will use a C ABI comptible struct layout, and ` packed ` will
1961
+ remove any padding between fields (note that this is very fragile and may
1962
+ break platforms which require aligned access).
1963
+
1944
1964
### Miscellaneous attributes
1945
1965
1946
1966
- ` export_name ` - on statics and functions, this determines the name of the
@@ -1958,12 +1978,6 @@ interpreted:
1958
1978
crate at compile-time and use any syntax extensions or lints that the crate
1959
1979
defines. They can both be specified, ` #[phase(link, plugin)] ` to use a crate
1960
1980
both at runtime and compiletime.
1961
- - ` repr ` - on C-like enums, this sets the underlying type used for
1962
- representation. Useful for FFI. Takes one argument, which is the primitive
1963
- type this enum should be represented for, or ` C ` , which specifies that it
1964
- should be the default ` enum ` size of the C ABI for that platform. Note that
1965
- enum representation in C is undefined, and this may be incorrect when the C
1966
- code is compiled with certain flags.
1967
1981
- ` simd ` - on certain tuple structs, derive the arithmetic operators, which
1968
1982
lower to the target's SIMD instructions, if any; the ` simd ` feature gate
1969
1983
is necessary to use this attribute.
0 commit comments