Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How C++ moves calculations from run time to compile time

Shulou Source: shulou.com Published: 2022-06-01 19:48:35 10月01日 Update

This article introduces the knowledge of "how C++ moves computing from runtime to compile time". Many people will encounter this dilemma in the operation of actual cases. next, let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!

Per.11: move calculations from run time to compile time

Reason (reason)

To reduce code size and execution time. Avoid data competition through constants. To catch errors at compile time (while eliminating error handling code)

Example (sample)

Double square (double d) {return dumped;}

Static double S2 = square (2); / / old-style: dynamic initialization

Constexpr double ntimes (double d, int n) / / assume 0

Tags: Compile code move run functions timing complexity constants clocking content objects situations data time more knowledge examples procedures errors storage Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Redmi Apple MySQL Huawei