I am surprised this compiles without any warning:
int main()
{
*"abc" = '\0';
}
with gcc main.c -Wall -Wextra and clang main.c -Weverything.
Why is there no warning for this ? Is there any way this could not raise a segmentation fault ?
I am surprised this compiles without any warning:
int main()
{
*"abc" = '\0';
}
with gcc main.c -Wall -Wextra and clang main.c -Weverything.
Why is there no warning for this ? Is there any way this could not raise a segmentation fault ?
Copyright © 2021 Jogjafile Inc.
You can use
-Wwrite-stringsto get a warning for this code in GCC. From the GCC documentation:"Is there any way this could not raise a segmentation fault ?" -> It is undefined behavior to modify a string litteral. So anything could happen, including not segfaulting.