beaver-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Beaver-devel] beaver_box_prompt


From: Tobias Heinzen
Subject: Re: [Beaver-devel] beaver_box_prompt
Date: Sat, 13 Sep 2008 13:54:19 +0200
User-agent: Thunderbird 2.0.0.16 (X11/20080724)

Double 12 wrote:
I have worked on the beaver_box_prompt function. The box works fine, but getting the inputted value to the rest of the program doesn't really. It is still not clear to me of which type the return value of the function should be (gchar, gchar* or const gchar*) to transfer the string in the right way. I hope you can teach me something about it ;)
gchar: single character
gchar*: pointer to the first character of a sequence of characters (aka. "string")

the const keyword is something like a write protection. if I declare a variable const, i can't overwrite it's value.

example. if i got a variable

const gchar foo = 'a';

then i can't do something like this after it's declaration.

foo = 'b';

I'm still able to read from it but not write. this is often used for parameters in functions, where this parameter is only used for reading. this is especially used when you do not want accidently overwrite the pointer. but carefull. even if I declare a variable

const gchar* foo = "Hello";

i still can do something like this

gchar* bar = foo;
bar[0] = 'B';

With pointers only the variable holding the pointer is write protected but not the data the pointer is pointing to.

since you get the data from a text entry widget (or something like that), you will receive a gchar* anyway (look at the gtk documentation what the functions return. mostly you want to return the same thing). gchar* is probably the right choice here (since i think you can't return a const variable in C). Also you have to check wheter or not the returned pointer has to be freed after use (that should also be written in the gtk documentation. most of the gtk get_text () (or something like that) functions require to free the space after use).

greetings
Tobias




reply via email to

[Prev in Thread] Current Thread [Next in Thread]