[Interest] How does one use Q_ASSUME?
René J.V. Bertin
rjvbertin at gmail.com
Sat May 25 11:33:15 CEST 2019
On Saturday May 25 2019 11:05:39 Elvis Stansvik wrote:
> E.g.
>
> Q_ASSUME(!atWar);
>
> if (atWar) {
> fireNukes(); <-- Oops, nukes may not be fired, even if at war,
> because compiler may have taken the hint and assumed we're not at war
> }
>
> Microsoft seems to have a nice article about their __assume (which
> Q_ASSUME expands to):
> https://docs.microsoft.com/en-us/cpp/intrinsics/assume?view=vs-2019
I'll have a look, maybe it confirms your idea of how this might be used.
> I don't understand. That just looks like an if statement?
Yes, one that could expand to
if (__assume(condition)) {
}
this would seem a bit more in line with comparable compiler directives that influence how (or if) branches are taken, like the *likely directives or llvm's __builtin_available directive.
R
More information about the Interest
mailing list