Valac: Compiling into C code: Expected semicolon in the wrong place
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
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.
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).
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 !
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.
...
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:
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.
//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 ?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.