Liste des Groupes | Revenir à cl c |
On 2024-08-01, Mark Summerfield <mark@qtrac.eu> wrote:
>This program segfaults at the commented line:>
>
#include <ctype.h>
#include <stdio.h>
>
void uppercase_ascii(char *s) {
while (*s) {
*s = toupper(*s); // SEGFAULT
s++;
}
}
>
int main() {
char* text = "this is a test";
The "this is a test" object is a literal. It is part of the
program's image. When you try to change it, you're making your
program self-modifying.
>
The ISO C language standard doesn't require implementations to
support self-modifying programs; the behavior is left undefined.
>
It could work in some documented, reliable way, in a given
implementation.
>
It's the same with any other constant in the program. [...]
Les messages affichés proviennent d'usenet.