Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have not any experience related to OpenCL. So mainly my answer is about C++ using.</p> <ol> <li><p><strong>Why cast is necessary?</strong> The cast is necessary, because you're declaring C array <code>properties[]</code> where each element should be of type <code>cl_context_properties</code>. Since cl_platform_id has different type it should be cast to appropriate type, exactly - <code>cl_context_properties</code>. You're using C-style cast that looks like this: (type_to_cast_to)(expression_to_be_cast). If <code>expression_to_be_cast</code> is just a variable like in you case you can omit parentheses around <code>expression_to_be_cast</code>:</p> <p>cl_context_properties properties[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[0], 0};</p></li> <li><strong>Why is there an extra set of brackets () at the end?</strong> You should use the brackets since variable <code>platform[0]</code> is of type <code>cl::Platform</code> which is not plain type (like int, char, double for example) and <code>cl::Platform</code> class is a wrapper. You should invoke operator() of this class in order to get underlying data of type <code>cl_platform_id</code> that you need. So next code should be simpler: <code>cl_context_properties properties[] = { CL_CONTEXT_PLATFORM, static_cast&lt;cl_context_properties&gt;(platforms[0]()), 0};</code></li> </ol> <p>Here you're doing cast with C++ style cast <code>static_cast</code> which is preferable cast in C++ ( <a href="http://en.cppreference.com/w/cpp/language/static_cast" rel="nofollow">you can read about it here</a> ) of object returned by invocation of <code>operator()</code> on object <code>platforms[0]</code>. The <code>operator()</code> is defined in class <code>cl::detail::Wrapper&lt; T &gt;</code> (<a href="http://kosobucki.pl/cl_doc/classcl_1_1detail_1_1Wrapper.html" rel="nofollow">class reference</a>) which is parent class for class <code>cl::Platform</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload