Page 1 of 1

How do you use "struct" on linux

PostPosted: Thu Oct 25, 2012 1:32 pm
by GEuser
Do any Linux users know what you need to do to use a struct in GE?

keep getting these errors:

Error line 3: Expected ;
Error line 4: Expected ;

Code used:-
Code: Select all
struct person
{
    int Age = 0;
};


I've tried all sorts of struct delcarations but it could just as easily be an issue with the linux version of GE. Any ideas?

Re: How do you use "struct" on linux

PostPosted: Thu Oct 25, 2012 4:06 pm
by MrJolteon
Try removing the semicolon from line 4.

Re: How do you use "struct" on linux

PostPosted: Thu Oct 25, 2012 4:23 pm
by GEuser
I've tried all the different permutations from online research so I know it's not typo issues, its to do with the actual gE version of linux or something else.

Maybe, I need additional libraries to use struct. Libraries specific for C as opposed to C++, header files or something of that sort. Not too knowledgeable on this front but thought struct was part of standard C library anyway so it should be included (not sure about this)?

Thanks for your reply.

Re: How do you use "struct" on linux

PostPosted: Thu Oct 25, 2012 8:14 pm
by skydereign
That is because you can't set default values for structs. Remove the = 0; when declaring the age variable and it will work.

Re: How do you use "struct" on linux

PostPosted: Fri Oct 26, 2012 1:04 am
by GEuser
WOW!!! it actually excepted it this time round.

I did as you instructed, this:
Code: Select all
struct person
{
     Age;
};


then I added it in Gobal Code Editor as person. The thing is how do I assign it a value to Age. How do I actually access it in the code.? Was I right to add it as person in Gobal Code Editor? Sorry to throw up so many questions but these structs would really be useful for some of the stuff I hope to do.

Really appreciate it Sky, thanks again :D

Re: How do you use "struct" on linux

PostPosted: Fri Oct 26, 2012 1:11 am
by skydereign
I assume you mean this by your code (otherwise you aren't creating an integer variable).
Code: Select all
struct person
{
    int Age;
}


You can think of a struct as a variable type (int, char, etc). You need to declare an actual variable using the struct you just defined. If you only want one global version of the struct, you can just add this to the bottom.
Code: Select all
struct person var_name;

That declares a person struct variable. To access the structs contents, you just use var_name.variable, in your case var_name.Age.

Re: How do you use "struct" on linux

PostPosted: Fri Nov 02, 2012 11:12 pm
by GEuser
Thanks!

think I'll leave these for another time.