uchar4 problem ! doesn't recognize the fourth vector i.e., w


The following is a part of a bigger code

1	  uchar4 result;

2	  if(sl.x>85)

3	result.x=255;

4	else

5		result.x=0;

6	   if(sl.y>85)

7		result.y=255;

8	else

9		result.y=0;

10	if(sl.z>85)

11		result.z=255;

12	else

13			 result.z=0;

14	 result.w=255;

The error is expected a “;” in line no 14

Can someone please explain how a “;” is missing there ?

Your indentation is absolutely horrible, fix that and check your code again. Perhaps thats not the actual error.

It has nothing to do with the indentation.

To make it more understandable, let me show the following code:

1	uchar4 result;

2	result.x=12;

3	result.y=24;

4	result.z=56;

5	result.w=31;

In the above piece of code, the error occurs at line number 5. If it is really about “;”, then it should show errors in lines 2, 3 and 4 also. But, the error is shown in line 5 only. I hope this explains my problem.

Yea bad indentation is not an error, but its very bad practice, it makes the program hard to read and hard to identify obvious errors. That piece of code compiles fine here. Could you show more code?

I would prefer sharing the code personally. Please leave u’re email ID. I will email the code to you. If its ok with you, we can also chat.

i’ve had similar trouble time to time,

the best method for me is to start commenting and doing extreme simple examples.

have you tried discarding the uchar4 thing? for example

float4 result;





I haven’t tried float4 yet, but the whole point of trying uchar4 is because of memory limitations in my code. For something that can be handled by uchar4, I didn’t want to waste the memory by using float4 which occupies more memory (almost 4 times).

I am attaching the completely compilable and perfectly runnable code which uses uchar3. This code is an experimental sobel edge detection using texture and shared memories. It compiles and runs absolutely fine when I use uchar3, but it doesn’t do the same for uchar4. If anyone can use uchar4 in the same code and let me know about the performance, that will be very helpful.
sobel_tex_shared.cu (7.4 KB)

Any solutions ?

uchar4s seem to work for me. What compiler version are you running?

I am using MS VS 2008 with cuda 3.0b.

Hi everyone, the problem is solved. A constant ‘w’ has been defined at the top of the code, which is conflicting with the fourth vector of the uchar4 data type. I know that declaring constants can conflict with any other variables in the code with the same name. But, I didn’t realize that they can conflict with one of the vectors of a built-in vector type. So, the ground rule is don’t define any constants with names ‘x’, ‘y’, ‘z’ or ‘w’ in a code which uses built-in vector types. I appreciate the help of all the people here. And, I hope my experience will help others on this issue.