简体   繁体   中英

OpenMP and C++: this pointer

Is this pointer always shared in OpenMP?

Compiler does not complain about following code, despite default(none) :

#pragma omp parallel for default(none), shared(n)
for ( SInt i = 0; i < n; ++i )
{
    f( i, this );  // f is some function.
}

The OpenMP standard defines data-sharing attribute rules for variables referenced in your code. Anyhow, according to the C++ standard draft (n3242 9.3.2) this is not a variable but a prvalue expression (emphasis mine):

In the body of a non-static (9.3) member function, the keyword this is a prvalue expression whose value is the address of the object for which the function is called. The type of this in a member function of a class X is X*. If the member function is declared const, the type of this is const X*, if the member function is declared volatile, the type of this is volatile X*, and if the member function is declared const volatile, the type of this is const volatile X*.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM