Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Vala-list Digest, Vol 26, Issue 8
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ali Sabil  
View profile  
 More options Jan 6 2010, 4:56 am
From: Ali Sabil <ali.sa...@gmail.com>
Date: Wed, 6 Jan 2010 10:56:39 +0100
Local: Wed, Jan 6 2010 4:56 am
Subject: Re: [Vala] Vala-list Digest, Vol 26, Issue 8

On Wed, Jan 6, 2010 at 10:20 AM, golnaz nilieh <g382nil...@gmail.com> wrote:

>> On Wed, Jan 6, 2010 at 7:28 AM, Jan Hudec <b...@ucw.cz> wrote:

>> > On Tue, January 5, 2010 13:12, Frederik wrote:
>> >> Non-value-type static class variables are only initialized after the
>> >> class was instantiated at least once. This behaviour is a little bit
>> >> counter-intuitive, and I hope it will change in the future.

>> > I have to disappoint you -- that behaviour can't change.

>> > The problem is, that the while the mechanism for static constructors
>> > exists for C++, there does not seem to be a portable way to use it from
>> > C (in gcc you can use the __attribute__((constructor)), but that's an
>> > extension).

>> >> You have several options:

>> >> - create a throw-away instance:

>> >> ? static int main (string[] args) {
>> >> ? ? ? new Global ();
>> >> ? ? ? stdout.printf ("all data is in: " + Global.dataDir);
>> >> ? ? ? return 0;
>> >> ? }

>> > Actually, there is no need to do that -- calling typeof(Global); is
>> > enough.

>> >> - call a static initialization method:

>> >> ? static int main (string[] args) {
>> >> ? ? ? Global.init ();
>> >> ? ? ? stdout.printf ("all data is in: " + Global.dataDir);
>> >> ? ? ? return 0;
>> >> ? }

>> > This should not work. *static* methods do not cause a class to be
>> > initialized (*class* methods do, though).

>> >> - make 'dataDir' const, if it is not intended to change

>> > - make the variable a class one instead of static one.

>> > public class Global {
>> > ? ?class string dataDir = "whatever";
>> > }

>> To me to correct way is to use:
>>    public static const string dataDir = "/usr/local/share/";
>> instead of:
>>    public static string dataDir = "/usr/local/share/";

>> Also please follow the Vala coding conventions (data_dir instead of
>> dataDir)

>> --
>> Ali

> Thanks to all. I defined an empty constructor for Global, and called it in
> main function. also I changed dataDir to a constant variable.

If you define dataDir as constant you don't need the constructor and
you don't need to call it.

> But a new question: Is there a way to pass the installation path to dataDir?
> I use this macro in configure.ac:

> AC_PREFIX_DEFAULT(/usr/local)

> can i use it as a variable in a vala source file?

I already posted a message about that in this mailing list, but it
seems like you are subscribing to a mail digest, it will take a while
before you get it.
_______________________________________________
Vala-list mailing list
Vala-l...@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.