sans changer le reste du programe , on a :
%gcc -ansi -pedantic helo.c -o gruik
tt.c: In function `main':
tt.c:12: warning: assignment discards qualifiers from pointer target type
tt.c:16: warning: assignment discards qualifiers from pointer target type
en c++:
%g++ hello.cpp -o gruikcpp
tt.cpp: In function `int main(int, char**)':
tt.cpp:12: error: invalid conversion from `const char*' to `char*'
tt.cpp:16: error: invalid conversion from `const char*' to `char*'
Et si on transforme sChaine en const char * , on ne peux plus le modifier a moins de faire un cast explicitement.
BTW autre avantage , au debuggage c'est plus facile car CHAINE1 est une vraie variable qu'on peut afficher.
[^] # Re: je ne fait que mon boulot ...
Posté par kesako . En réponse au message Chaines constantes.... Évalué à 6.
avec
const char * const CHAINE1 ="coin coin !\n";
const char * const CHAINE2 ="pan !\n";
sans changer le reste du programe , on a :
%gcc -ansi -pedantic helo.c -o gruik
tt.c: In function `main':
tt.c:12: warning: assignment discards qualifiers from pointer target type
tt.c:16: warning: assignment discards qualifiers from pointer target type
en c++:
%g++ hello.cpp -o gruikcpp
tt.cpp: In function `int main(int, char**)':
tt.cpp:12: error: invalid conversion from `const char*' to `char*'
tt.cpp:16: error: invalid conversion from `const char*' to `char*'
Et si on transforme sChaine en const char * , on ne peux plus le modifier a moins de faire un cast explicitement.
BTW autre avantage , au debuggage c'est plus facile car CHAINE1 est une vraie variable qu'on peut afficher.