Hi

C++ requires constant expressions to be known during compilation, not
at link time.

A constant that is not determined at compile-time is akin to
constructor that is const but not constexpr. While it remains
constant throughout the program, its value is established only
at link-time, not at compile-time.

That is not valid.
http://eel.is/c++draft/expr.sizeof#note-3
says that sizeof is an integral constant expression, so it can be used in
consteval or constexpr function constant evaluation or in constant
expressions.  You can't defer that to link time evaluation, the exact
values of the constant expressions may affect which templates are
instantiated etc., you'd basically need to defer all the compilation until
link time then.

I understand the concerns about the C++ standard requiring constant
expressions to be known during compilation. However, my proposal for
link-time evaluation offers significant flexibility and efficiency
improvements that could address current limitations in compile-time
constant expressions.

To ensure compatibility with existing C++ standards, we could:

1. Introduce a hybrid approach where essential constant expressions
are still resolved at compile-time, while less critical ones can be
deferred to link-time.

2. Provide clear guidelines and use cases for when and how link-time
constants should be used to avoid impacting template instantiation.

I believe this approach balances the advantages of link-time flexibility
with the needs of compile-time constant evaluations. I'd be happy to
discuss this further with specific examples and implementation
strategies.

To be honest, I currently have no intention of using link-time constants
for purposes other than the following:

----------------------------------------------------------------------
struct Vec {
    int x, y, z;
};

struct Pix : Vec {
    int r, g, b;
};
----------------------------------------------------------------------
    |
    |
    V
----------------------------------------------------------------------

// Linkable constant
int __offset_of_x_in_Pix = __offset_of_x_in_Vec;
int __offset_of_y_in_Pix = __offset_of_y_in_Vec;
int __offset_of_z_in_Pix = __offset_of_z_in_Vec;
int __offset_of_r_in_Pix = __sizeof_Vec;
int __offset_of_g_in_Pix = __offset_of_r_in_Pix + __sizeof_int;
int __offset_of_b_in_Pix = __offset_of_g_in_Pix + __sizeof_int;
int __sizeof_Pix = __offset_of_b_in_Pix + __sizeof_int;

----------------------------------------------------------------------


Reply via email to