Reputation: 2037
I want to define two functions with the same name but one applying a transformation on a float4 and the other one apply a transformation on float3 but it says:
conflicting types for 'mult'
Is it impossible or something is wrong in my code?
typedef struct {
float m[16]; // member elements of the matrix
} mat4;
typedef struct {
float m[9];
} mat3;
float4 mult(mat4 matrix, float4 p) {
return
matrix.m[0] * p.x + matrix.m[1] * p.y + matrix.m[2] * p.z + matrix.m[3] * p.w +
matrix.m[4] * p.x + matrix.m[5] * p.y + matrix.m[6] * p.z + matrix.m[7] * p.w +
matrix.m[8] * p.x + matrix.m[9] * p.y + matrix.m[10] * p.z + matrix.m[11] * p.w +
matrix.m[12] * p.x + matrix.m[13] * p.y + matrix.m[14] * p.z + matrix.m[15] * p.w ;
}
float3 mult(mat4 matrix, float3 p) {
return mult(matrix, float4(p, 1)).xyz;
}
Upvotes: 2
Views: 1570
Reputation: 9925
Although the OpenCL built-in functions utilise function overloading to provide different variants of the same function with the same name, the OpenCL C specification does not explicitly allow function overloading in user code (and this is not a feature of C99 either).
It might be that some of the Clang-based OpenCL implementations let you use the overloadable
function attribute, which would look something like this:
float4 __attribute__((overloadable)) mult(mat4 matrix, float4 p) {
...
}
float3 __attribute__((overloadable)) mult(mat4 matrix, float3 p) {
...
}
This is not a standard OpenCL feature however, and is not guaranteed to work on all OpenCL platforms. The OpenCL C++ kernel language proposed for OpenCL 2.1 will natively support function overloading.
Upvotes: 3