Похожие чаты

If we do not use constexpr , will the same

program do calculation at compile time or at run time ? see this example https://pastebin.com/yAh9eyDN

10 ответов

12 просмотров

Well for that simple code, if you don't disable optimization, the value stored in x would be 200. Assuming you don't do optimization, and you add constexpr specifier to the function, yes the calculation will be done at compile time. x would be 200

Peace
what kind of optimization ?

compilers usually do optimization by default, you can enable, disable these using compiler flags

Peace
what kind of optimization ?

What compiler do you normally use? msvc? gcc, clang?

Peace
gcc

https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

Peace
what kind of optimization ?

ah i forgot to mention, constexpr doesn't gurantee that the expression will be evaluated during compile time :D

constexpr guaranties compile time calculation. Non-constexpr may or may not be optimized away, unless you disable optimization, and then it will, well, not optimized

Похожие вопросы

Обсуждают сегодня

Всем привет! Имеется функция: function IsValidChar(ch: UTF8Char): Boolean; var i: Integer; ValidChars: AnsiString; begin ValidChars := 'abcdefghijklmnopqrstuvwxyzABCDE...
Евгений
44
For all those that keep asking why no pump? why this ? and why that...? Please close ur ewt chart and open 2 others - TOTAL (total mc) and BTC.D (btc dominance). Maybe BTC a...
Inn3r_G
19
"Since pnut can flip FTM easily, I'm swapping my FTM to pnut and hoping for a easy x5-x10" Perfect recipe for disaster. NFA but chances are, you'll end up as exit liquidity ...
C. A.
7
AMD status update? No longer in the plan but something might be around the corner later on Chinese partner? No longer in the plan. This market does not seem to be the top ...
Ben
6
Добрый день, подскажите, пожалуйста, по проблеме. Сегодня на работе утром обнаружилось что по рдп подключиться не получается к серверу 2022. В серверную зашел - на системно...
srv
19
Ready for some fun AND a chance to win TKO Tokens? Join us for exciting minigames in our Telegram group! 🕒 Don’t miss out—games start on today 25 October 2024, at 8 PM! Ge...
Milkyway | Tokocrypto
255
Чтобы перехватить все нажимания буков на форме, надо хук ставить? Пробовал на форме ОнКейДаун, оно ловит клаву если фокус не на компоненте с вводом текста
Serjone
15
лучше скажите, причём тут паскаль?
Alexey Kulakov
36
Hey Why do I need headers files in c++ code when creating non library program? does it possible to import namespace without headers?
Jacob
12
Всем привет! вывожу на общей стр дочерние ресурсыв каждом ресурсе галерея, и первая фотка должна выводиться на общей [!DocLister? &prepare=photo !]
Alekso
12
Карта сайта