Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 C / OpenGL question..
Index -> Programming, C -> C Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
odi3




PostPosted: Wed Nov 28, 2007 12:28 pm   Post subject: C / OpenGL question..

C / opengl question:

Can i do this?

code:



    typedef struct
    {
      int i;
    }widget;

    display(void){
       widget newWidget2;
       newWidget2.i = 5;

       newWidget1 = newWidget2; // Can i update widget1.i using this line?
    }

    void main(){
       widget newWidget1;
    ...
       glutDisplayFunc(display);
    ...

    }


thanks!
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Wed Nov 28, 2007 12:41 pm   Post subject: RE:C / OpenGL question..

The first issue with this code is that newWidget1 is declaired in the main function. This means it only has scope in the main function and can not be accessed in display like you are doing.

You probly whont to decalire newWidget1 in display or golbaly.

Also the display function needs a type (probly void) this is probly just a type-o in the code you posted.

Behond all that, the line you commented will work. It will make newWidget1 a copy of newWidget2 with all of the same values.

Here is a small demo i made of it:

c:

 #include <stdio.h>
 #include <stdlib.h>
 
 typedef struct
    {
      int i;
    }widget;

    int main(){
       widget newWidget1;
       
       widget newWidget2;
       newWidget2.i = 5;

       printf("%d\n", newWidget2.i);

       newWidget1 = newWidget2;
       
       printf("%d\n", newWidget1.i);
       
       newWidget1.i = 10;
       
       printf("%d\n", newWidget2.i);
       printf("%d\n", newWidget1.i);
       
       getchar();
       return 0;
    }


Edit: Note that the above code is just to show that newWidget1 = newWidget2; makes a copy of newWidget2 in newWidget1 of shorts and does not just point to it. You should not copy and past this code in to your program as it does nothing usefull :p
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
odi3




PostPosted: Wed Nov 28, 2007 1:50 pm   Post subject: Re: C / OpenGL question..

ah ok,

I was thinking since display was being referenced in main, that it would inherit the objects...

guess not haha,

thnx
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: