Thread: error: invalid operands to binary *

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    29

    error: invalid operands to binary *

    How the heck am I getting this error?

    error: invalid operands to binary *

    Code:
    *(yuv->y + i) = (0.257) * (image->data + (i*3)) + 
    						(0.504) * (image->data + (i*3+1)) + 
    						(0.098) * (image->data + (i*3+2)) + 16;
    						
    		*(yuv->u + i) = (0.439) * (image->data + (i*3)) + 
    						(0.368) * (image->data + (i*3+1)) - 
    						(0.071) * (image->data + (i*3+2)) + 128;
    						
    		*(yuv->v + i) =(-0.148) * (image->data + (i*3)) - 
    						(0.291) * (image->data + (i*3+1)) + 
    						(0.439) * (image->data + (i*3+2)) + 128;
    Disk space: the final frontier

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    29
    I missed the dereference pointer *. But still one error. Thanks for viewing.


    Code:
    		*(yuv->y + i) = (0.257) * (*image->data + (i*3)) + 
    						(0.504) * (*image->data + (i*3+1)) + 
    						(0.098) * (*image->data + (i*3+2)) + 16;
    						
    		*(yuv->u + i) = (0.439) * (*image->data + (i*3)) + 
    						(0.368) * (*image->data + (i*3+1)) - 
    						(0.071) * (*image->data + (i*3+2)) + 128;
    						
    		*(yuv->v + i) =(-0.148) * (*image->data + (i*3)) - 
    						(0.291) * (*image->data + (i*3+1)) + 
    						(0.439) * (*image->data + (i*3+2)) + 128;
    Disk space: the final frontier

  3. #3
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    maybe some more context..
    also if you are derefrence why are you still using -> ?
    should it not be

    (*image).data

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    29
    Just to avoid confusion with C++ and OOP
    Disk space: the final frontier

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    95

    It compiled good for me

    if your data structs are like this :

    Code:
    struct test1
       {
       int    *data;
       };
    
    struct test2
       {
       int   *y;
       int   *u;
       int   *v;
       };
    
    
    struct test1 *image;
    struct test2 *yuv;
    Please don't try to run it like this.

  6. #6
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Quote Originally Posted by cblix
    I missed the dereference pointer *. But still one error. Thanks for viewing.


    Code:
    		*(yuv->y + i) = (0.257) * (*image->data + (i*3)) + 
    						(0.504) * (*image->data + (i*3+1)) + 
    						(0.098) * (*image->data + (i*3+2)) + 16;
    						
    		*(yuv->u + i) = (0.439) * (*image->data + (i*3)) + 
    						(0.368) * (*image->data + (i*3+1)) - 
    						(0.071) * (*image->data + (i*3+2)) + 128;
    						
    		*(yuv->v + i) =(-0.148) * (*image->data + (i*3)) - 
    						(0.291) * (*image->data + (i*3+1)) + 
    						(0.439) * (*image->data + (i*3+2)) + 128;
    i hope u havn't clear under stood the structs with pointers concept. in many places u have used this
    Code:
    *image->data
    the use of -> operator is b'cose of problem which we face at the operator precedence. let me explain u clear.
    Code:
    (*image.data)
    looking at the code above u might guess that the code actually access the data members of the structure. but the fact is, it don't, but still looks like we are accessing it. the problem here is the * operator has more precedence than '.'. what we are actually expexting here to do is to get the data from the struct data member 'data' and dereferece to get the actual data out of it. thats was we are expecting.

    in order to overcome this problem we starting useing -> operator which has more precedence than '.' and '*'. so it access it and derefereces it. having understood this u can now change your code to look soemthing as follow:
    Code:
    image->data
    which look more meaning full now.

    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. invalid operands to binary ^ ?
    By seal in forum C Programming
    Replies: 14
    Last Post: 09-13-2005, 04:59 PM
  2. Need help with C program
    By ChrisH in forum C Programming
    Replies: 38
    Last Post: 11-13-2004, 01:11 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. misc.c:3210: invalid operands to binary +
    By Unregistered in forum Linux Programming
    Replies: 2
    Last Post: 07-19-2002, 07:00 AM