Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Can const be inferred from invariant?

const inferred invariant
0
Posted

Can const be inferred from invariant?

0

There was some discussion on whether const and invariant needed to be two separate keywords. I believe that they do. The reason is that they express different guarantees, and thus give the programmer the opportunity to demand the stronger or weaker guarantee. To wit: void threadTask(const T* work) { … } void threadTask(invariant T* work) { … } In the first example, the thread doesn’t need to lock access to work unless it needs a consistent read of different parts of work. In the second example, access to work never needs to be locked. If you took away one of the keywords and let the proper case be inferred, I would never be able to claim one of the guarantees and make the distinction between these two functions (which, for performance reasons, could be significant).

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.