[Interest] How does one use Q_ASSUME?

Marian Beermann public at enkore.de
Sat May 25 11:45:51 CEST 2019


> if (__assume(condition)) {
> }

would generally be considered equivalent to

if(1) {
}

which we could just write as

{}

-Marian

Am 25.05.19 um 11:33 schrieb René J.V. Bertin:
> 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
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
> 




More information about the Interest mailing list