j'imagine, toute variable statique n'est initialisée qu'au moment du premier appel (à vérifier néanmoins).
Arrête d'imaginer et vérifie. Les variables static initialisées à autre chose que 0 vont dans la section data au lieu de BSS (comme indiqué par neologix et GLMF#2^7) :
$ cat t.c
#include <stdio.h>
#include <stdlib.h>
static int s(int d)
{
static int zero;
static int quarantedeux = 42;
return d + zero + quarantedeux;
}
int main(int argc, char **argv)
{
printf("%d\n", s(atoi(argv[1])));
return 0;
}
$ cc -O0 -o t.so t.c
$ nm t | egrep 'zero|qua'
0000000000600968 d quarantedeux.2396
0000000000600980 b zero.2395
pertinent adj. Approprié : qui se rapporte exactement à ce dont il est question.
[^] # Re: Re:Re:Sécurité ?
Posté par Krunch (courriel, site web personnel) . En réponse à la dépêche Un nouveau serveur httpd : Ashd, A Sane HTTP Daemon. Évalué à 2.
$ cat t.c #include <stdio.h> #include <stdlib.h> static int s(int d) { static int zero; static int quarantedeux = 42; return d + zero + quarantedeux; } int main(int argc, char **argv) { printf("%d\n", s(atoi(argv[1]))); return 0; } $ cc -O0 -o t.so t.c $ nm t | egrep 'zero|qua' 0000000000600968 d quarantedeux.2396 0000000000600980 b zero.2395pertinent adj. Approprié : qui se rapporte exactement à ce dont il est question.