LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 10-20-2010, 09:58 PM   #1
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 54
Valac: Compiling into C code: Expected semicolon in the wrong place


Here is my problem: I have a Vala program that includes classes with nested classes. When I try to initialize classes (using the variable type and the variable, followed by the class's arguments [three unsigned 8-bit integers] in parentheses) and try to compile the Vala code to C code (thanks Steshenko, that's what I tried to AVOID doing, as I really wanted to create a shared object file, but now I know I have to use C code as a middleman), the compiler tells me it expects a semicolon between the class variable name and its members.

What?! A semicolon in a bad place, that's for sure! Why would I want to put a semicolon *BETWEEN* the class initialization and its members? Isn't the whole point of a class to *HAVE* different members?

Here is my class:

Code:
public class Gtk.rgba : GLib.Object {
    public class fg_color : GLib.Object {
        private uint8 red;
        private uint8 green;
        private uint8 blue;
		
        //Constructor
        public fg_color(uint8 r, uint8 g, uint8 b) {
            r = red;
            g = green;
            b = blue;
			
            uint full_color = red * green * blue;
        }
    }
	
    public class bg_color : GLib.Object {
        private uint8 red;
        private uint8 green;
        private uint8 blue;
		
        //Constructor
        public bg_color(uint8 r, uint8 g, uint8 b) {
            r = red;
            g = green;
            b = blue;
			
            uint full_color = red * green * blue;
        }
    }
	
    //Toplevel constructor
    public rgba(var bg, var fg) {
        bg = bg_color;
        fg = fg_color;
    }
	
    public static void init(double alpha) {
        double alpha_t = alpha;

        //Here's where the error is
        for (alpha_t > 0; alpha_t < 1; ++alpha_t) {
            fg_color fg_increment(red++, green++, blue++);
            bg_color bg_decrement(red--, green--, blue--);
                                 ^ //The compiler is telling me to put a semicolon *HERE* <yawn>.
        }
    }
}

Last edited by Kenny_Strawn; 10-20-2010 at 10:57 PM.
 
Old 10-21-2010, 12:39 AM   #2
Anisha Kaul
Senior Member
 
Registered: Dec 2008
Location: Gurgaon, India
Distribution: Slackware 13.37, OpenSuse 11.3
Posts: 4,373
Blog Entries: 21

Rep: Reputation: 706Reputation: 706Reputation: 706Reputation: 706Reputation: 706Reputation: 706Reputation: 706
Shouldn't there be a semicolon at the end of the nested classes too ?
 
Old 10-21-2010, 01:01 AM   #3
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Original Poster
Rep: Reputation: 54
Yeah, inserting semicolons at the end of the nested classes causes more errors. This is Vala we're talking about here, the programming language written for the GNOME project that uses GLib as the standard library, has a syntax very much like Java's and C#'s, and compiles to C. You must have mistaken it for Java; that happens often.
 
Old 10-21-2010, 01:05 AM   #4
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Original Poster
Rep: Reputation: 54
Besides, Anisha: Here's the whole point of this post.

Notice the comments in my code pointing you to the location of the "error"? Scroll to the bottom of the code block, and you'll find them, as well as an upward-pointing carat pointing you to the location of just WHERE the compiler is telling me to insert the semicolon (Hint: It's in an odd location).
 
Old 10-21-2010, 01:21 AM   #5
Anisha Kaul
Senior Member
 
Registered: Dec 2008
Location: Gurgaon, India
Distribution: Slackware 13.37, OpenSuse 11.3
Posts: 4,373
Blog Entries: 21

Rep: Reputation: 706Reputation: 706Reputation: 706Reputation: 706Reputation: 706Reputation: 706Reputation: 706
Well yes I mistook it for C++ and I am sorry for taking your thread off the zero reply list !

I saw your bolded code text earlier and the reason I pointed to the class semicolons was that compiler often points out to the wrong place w.r.t semicolons in C/C++ !

Check whether the functions are supposed to be called the way you have called them ?
I know you must have already seen this page:
http://www.linux.com/archive/feature/154784

and you can report my post for deletion in order to keep your thread in the zero reply list !
 
Old 10-21-2010, 01:23 AM   #6
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,352

Rep: Reputation: 129Reputation: 129
Sometimes errors propagate through to give unusual error messages.

So do you need to have semi-colons to end the nested classes? If so put them there and then check and fix the new error messages that appear.

Completely unrelated to your compiler errors but I don't think that the following does what you want it to do.
Code:
            r = red;
            g = green;
            b = blue;
 
Old 10-21-2010, 01:37 AM   #7
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,352

Rep: Reputation: 129Reputation: 129
Another point I don't think that your outer class knows about the identifiers red, green or blue.

Again unrelated to the compiler errors but you will probably have a hard time distinguishing the difference between the fg_color and bg_color, they are almost identical.
 
Old 10-21-2010, 01:57 AM   #8
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Original Poster
Rep: Reputation: 54
The following functions are constructors:

Code:
...
public fg_color(uint8 r, uint8 g, uint8 b) {
    r = red;
    g = green;
    b = blue;
    uint8 full_color = red * green * blue;
}
...
public bg_color(uint8 r, uint8 g, uint8 b) {
    r = red;
    g = green;
    b = blue;

    uint full_color = red * green * blue;
}
They are for one purpose: class construction, so you can use private numerical values (the 'red', 'green', and 'blue' values) publicly: when initializing the class, you do it like a function:

Code:
Gtk.rgba.bg_color foo(17, 17, 17);
Gtk.rgba.fg_color bar(241, 93, 44);
Then, you use the 'Gtk.rgba.init()' function to initialize the alpha value. Now let's try this again:

Code:
Gtk.rgba.bg_color foo(17, 17, 17);
Gtk.rgba.fg_color bar(241, 93, 44);
Gtk.rgba.init(0.5);
And besides: If GTK+ itself has values with the same names as these in a C struct (located in gdk/gdkcolor.h), why won't this do the same thing?
 
Old 10-21-2010, 01:58 AM   #9
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Original Poster
Rep: Reputation: 54
Quote:
Originally Posted by graemef View Post
Again unrelated to the compiler errors but you will probably have a hard time distinguishing the difference between the fg_color and bg_color, they are almost identical.
One is for the foreground and one is for the background; other than that they *ARE* identical.
 
Old 10-21-2010, 02:05 AM   #10
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Original Poster
Rep: Reputation: 54
These are the errors I get when I put semicolons at the end of the nested classes:

Code:
kenny_strawn@kenny-AOA110:~/Documents$ valac --pkg=gtk+-2.0 gtk_rgba.vala -H gtk_rgba.h
gtk_rgba.vala:18.6-18.6: error: syntax error, statements outside blocks allowed only in root namespace
   	};
   	 ^
gtk_rgba.vala:33.3-33.3: error: syntax error, statements outside blocks allowed only in root namespace
	};
	 ^
gtk_rgba.vala:44.25-44.25: error: syntax error, expected `;'
			fg_color fg_increment(red++, green++, blue++);
			                     ^
Compilation failed: 3 error(s), 0 warning(s)
kenny_strawn@kenny-AOA110:~/Documents$
The last error is what I already had before the semicolons at the end of the classes.

Last edited by Kenny_Strawn; 10-21-2010 at 02:07 AM.
 
Old 10-21-2010, 02:11 AM   #11
Anisha Kaul
Senior Member
 
Registered: Dec 2008
Location: Gurgaon, India
Distribution: Slackware 13.37, OpenSuse 11.3
Posts: 4,373
Blog Entries: 21

Rep: Reputation: 706Reputation: 706Reputation: 706Reputation: 706Reputation: 706Reputation: 706Reputation: 706
Code:
//Here's where the error is
        for (alpha_t > 0; alpha_t < 1; ++alpha_t) {
            fg_color fg_increment(red++, green++, blue++);
            bg_color bg_decrement(red--, green--, blue--);
                                 ^ //The compiler is telling me to put a semicolon *HERE* <yawn>.
        }
Where are the bolded functions defined in your code ? As I can see you have called them here. To which class do they belong ?
 
Old 10-21-2010, 02:59 AM   #12
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Original Poster
Rep: Reputation: 54
Those are initializations of the bg_color and fg_color classes, as declared before the functions (in turn within a function definition):

Code:
...
public static void init(double alpha) {
    int alpha_t = alpha;
    for(alpha_t > 0; alpha_t < 1; ++alpha_t) {
        fg_color fg_increment(red++, green++, blue++);
        bg_color bg_decrement(red--, green--, blue--);
    }
}
And what this function is supposed to do is this:

While the alpha value is between 0 and 1 and increments, the foreground color is supposed to increment and the background color decrement. This is literally what drives alpha blending: the background (at a lower alpha value) is supposed to blend into the foreground. This is how you get the look of partially transparent colors.
 
Old 10-21-2010, 02:59 AM   #13
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,352

Rep: Reputation: 129Reputation: 129
anishakaul My interpretation is that the bold values are object of type fg_color and bg_color respectively.

Kenny_Straw As I read the code red, green and blue are properties of the inner classes and not visible at the outer class level. That is what the compiler is complaining about and importantly this occurs on the line prior to the one you had indicated. Which means that the compiler message does make some sense.
 
Old 10-21-2010, 03:02 AM   #14
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,352

Rep: Reputation: 129Reputation: 129
I'd like to emphasis the point I gave earlier.
Code:
            r = red;
            g = green;
            b = blue;
The above is wrong. Your assignments are the wrong way around.
 
Old 10-21-2010, 03:28 AM   #15
Anisha Kaul
Senior Member
 
Registered: Dec 2008
Location: Gurgaon, India
Distribution: Slackware 13.37, OpenSuse 11.3
Posts: 4,373
Blog Entries: 21

Rep: Reputation: 706Reputation: 706Reputation: 706Reputation: 706Reputation: 706Reputation: 706Reputation: 706
I had missed post 8 *sigh*

Oh yes, it should be the other way round, now I do notice it too..

red = r;
green = g;
blue = b;

Quote:
Originally Posted by graemef View Post
Another point I don't think that your outer class knows about the identifiers red, green or blue.
Yes, C++ doesn't allow that too ! Vala must not be too different.
http://publib.boulder.ibm.com/infoce...%2Fcplr061.htm

Last edited by Anisha Kaul; 10-21-2010 at 03:38 AM.
 
  


Reply

Tags
expected-semicolon, vala, wrong-place


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
c code not running as expected isamuede Programming 6 04-28-2010 09:21 PM
Mail going to wrong place? alitrix Linux - Server 1 06-15-2008 01:58 PM
compiling looking in the wrong place for a libtool archive kryptobs2000 Linux - Software 5 01-05-2007 10:31 PM
I own everything! (did 'chown -R' in the wrong place) oskar Linux - Newbie 9 03-19-2006 05:38 PM
lilo in wrong place, help! krgue Linux - Software 4 05-22-2001 04:32 PM


All times are GMT -5. The time now is 06:02 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration