Conditional compilation using compile-time logic?


#1

Is it possible to perform conditional compilation on the basis of a compile-time constant? So, for example, in pseudocode:

const CONST: i32 = 3;

#[cfg(CONST > 4)]
...

If this isn’t possible for arbitrary code, is it possible for the implementation of a given type (e.g., along the lines of impl<T: Sized>, such as impl<CONST > 4, T: Sized>)?


#2

Conditional compilation is only based on boolean logic of features and the target environment. Not sure what you’re doing but you could use features as binary.


#3

For context, I’m trying to have different definitions of a type depending on the size of virtual memory pages on the target architecture. See: Get page size of target platform


#4

I don’t think page size is something that will be constant for a particular architecture. According to the libc manual “[page sizes] can possibly even vary among different processes on the same system”. You’ll need to find out at runtime and adjust your code accordingly.


#5

Yeah, that’s what somebody said in the other thread. Oh well. Thanks!