Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[OT] Gtk-Programmierung
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum
View previous topic :: View next topic  
Author Message
Linuxpeter
Guru
Guru


Joined: 28 May 2004
Posts: 403
Location: Dresden, Germany

PostPosted: Thu Jul 08, 2004 5:42 am    Post subject: [OT] Gtk-Programmierung Reply with quote

Ich habe eine kleine Frage: Wann sollte man eine Funktion mit static deklarieren und wann nicht?
_________________
Regards, Linuxpeter
Wenn "Windows" die Antwort ist, war es eine dumme Frage. ;-)
Is "Windows" the answer, then it was a stupid question. ;-)
Back to top
View user's profile Send private message
ruth
Retired Dev
Retired Dev


Joined: 07 Sep 2003
Posts: 640
Location: M / AN / BY / GER

PostPosted: Thu Jul 08, 2004 7:53 am    Post subject: Reply with quote

hi,
da musst du zwischen zwei fällen unterscheiden:
deklaration innerhalb und ausserhalb einer funktion.
eine statische deklaration ausserhalb einer funktion sorgt dafür, dass die variable nur innerhalb des aktuellen source files sichtbar ist(zum beispiel kann man dadurch leicht buf oder ähnliche vielfach verwendete variablennamen sichern, sozusagen... ( auch int i, z.b. ;-) )
oder doch besser static int ??? *grins*
innerhalb einer funktion bewirkt eine statische deklaration, dass erstens diese variable nur innerhalb der funktion sichtbar ist und zweitens, dass der wert der variable auch nach dem aufruf der funktion (und nach dem verlassen selbiger) bei einem erneuten aufruf wieder zur verfügung steht...
du siehst also - es kommt drauf an, was du tun willst... *grins*

gruss
rootshell
_________________
"The compiler has tried twice to abort and cannot do so; therefore, compilation will now terminate."
-- IBM PL/I (F) error manual
Back to top
View user's profile Send private message
Earthwings
Bodhisattva
Bodhisattva


Joined: 14 Apr 2003
Posts: 7753
Location: Germany

PostPosted: Thu Jul 08, 2004 8:55 am    Post subject: Reply with quote

Zu den Varianten bezüglich statischer Funktionen/Konstanten gibts hier mehr, aber Linuxpeter meint wohl mehr statische Funktionen.

@Linuxpeter: Wieso *Gtk*-Programmierung?
Back to top
View user's profile Send private message
mrsteven
Veteran
Veteran


Joined: 04 Jul 2003
Posts: 1938

PostPosted: Thu Jul 08, 2004 9:05 am    Post subject: Reply with quote

Du redest schon über C, @Linuxpeter, oder?
static bedeutet, der Name der Funktion ist nur innerhalb der Quelldatei bekannt, in der die Funktion steht. Du kannst also deine Funktion statisch definieren, wenn du die Funktion nur in einer Quelldatei brauchst.
Bei mir sind aber immer alle Funktionen extern.

In C++ bedeutet "static" bei Memberfunktionen, dass die Funktion eine Klassenfunktion ist und auch ohne Instanz der Klasse aufgerufen werden kann, z.B:
Code:

class foo
{
   public:
   static void bar();
   //...
};

int main()
{
   foo::bar();
   return 0;
}

_________________
Unix philosophy: "Do one thing and do it well."
systemd: "Do everything and do it wrong."
Back to top
View user's profile Send private message
ruth
Retired Dev
Retired Dev


Joined: 07 Sep 2003
Posts: 640
Location: M / AN / BY / GER

PostPosted: Thu Jul 08, 2004 9:36 am    Post subject: Reply with quote

hi,
oops, das hat er etwas zu schnell gelesen, der flo heute morgen...
hab nur gesehen: deklarieren... *träum* ... statisch... *gähn* *kaffee-such*
hab ich's halt auf variablen und nicht auf funktionen bezogen... :oops:
naja, kann passieren... ;)

gruss
rootshell
_________________
"The compiler has tried twice to abort and cannot do so; therefore, compilation will now terminate."
-- IBM PL/I (F) error manual
Back to top
View user's profile Send private message
Linuxpeter
Guru
Guru


Joined: 28 May 2004
Posts: 403
Location: Dresden, Germany

PostPosted: Thu Jul 08, 2004 2:18 pm    Post subject: Reply with quote

Erst mal Dank an alle!

Und ja klar, ich meine natürlich C. :oops:

Was es damit in C++ auf sich hat, wußte ich schon Qt,
nur eben in Gtk (C) war es mir nicht klar. :roll:

Dann noch eine Frage: Hat jemand einen Link zu einer
deutschprachigen gettext-Dokumentation?
_________________
Regards, Linuxpeter
Wenn "Windows" die Antwort ist, war es eine dumme Frage. ;-)
Is "Windows" the answer, then it was a stupid question. ;-)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum