我发现了类似的问题Compile-time generic type size check,但没有收到任何答案。在编译时检查指针大小
问题是通过FFI +不安全,与其他编程语言合作, 我想确保mem::size_of::<*mut T>()
具有适当的大小。 我发现在互联网这样的static_assert
宏:
macro_rules! static_assert {
(type $t:ty;) => (
type __StaticAssert = $t;
);
(type $t:ty; $e:expr $(, $ee:expr)*) => (
static_assert!(type ($t, [i8; 0 - ((false == ($e)) as usize)]); $($ee),*);
);
($e:expr $(, $ee:expr)*) => (
static_assert!(type [i8; 0 - ((false == ($e)) as usize)]; $($ee),*);
);
}
static_assert!(2 == 2);
它的工作原理,但如果我用mem::size_of::<*const f64>()
内宏观所有失败 因为,:calls in constants are limited to struct and enum constructors
, 任何想法如何计算size_of
*const f64
在编译时?
如果另一个问题没有收到答案,打开副本并不是一种方式,如果您想增加另一个问题的可见性,请考虑添加[bounty](http://stackoverflow.com/help/)赏金)它 –
它看起来不是一个完整的重复给我,你能展开这个问题不同于[这个相关的问题](http://stackoverflow.com/questions/30330519/compile-time-generic-type-大小检查)你链接? –
'mem :: size_of'在编译时尚未评估。等一年,故事可能会改变(但也许不会,谁知道?)。 – Veedrac