Hello, I am trying to insert the following code into .cl file. I can’t compile the .cl file. This is a bug for CUDA, but what about OpenCL? Is it a bug for OpenCL too? Thanks!
[codebox]struct Vector3
{
float x, y, z;
Vector3( float x_ = 0, float y_ = 0, float z_ = 0 )
{
x = x_;
y = y_;
z = z_;
}
OpenCL is based on C99 and doesn’t support C++ features like constructors or member functions. (For the record, CUDA doesn’t support constructors on the device either, but does support simple member functions).
OpenCL is pure C99, not “C subset of C++”. In C, you can’t have functions in structs. Well, you could have function pointers if you really wanted to, but deffinitely not a native constructor :) And I’m pretty sure a function pointer would be invalid on the device anyway.
In C++ the difference between struct and class is only the default visibility of arguments and methods (private in class, public in struct). Otherwise they are semantically identical and you can have constructors in C++ structs. Not in C.
Edit: Simon has the quickest submit button on the west.