Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
I have heard that it is undefined behaviour to make a pointer point outside boundaries of an array even without dereferencing it. Can that really be true? Consider this code: int main(void) { ...
#3: Post edited
- I have heard that it is undefined behaviour to make a pointer point outside boundaries of an array even without dereferencing it. Can that really be true? Consider this code:
- int main(void)
- {
- char arr[10];
char *ptr = arr[-1];- char c = *ptr;
- }
The line `char c = *ptr` is obviously bad, because it's accessing out of bounds. But I heard something that even the second line invokes undefined behaviour? Is this true? What does the standard say?
- I have heard that it is undefined behaviour to make a pointer point outside boundaries of an array even without dereferencing it. Can that really be true? Consider this code:
- int main(void)
- {
- char arr[10];
- char *ptr = &arr[-1];
- char c = *ptr;
- }
- The line `char c = *ptr` is obviously bad, because it's accessing out of bounds. But I heard something that even the second line `char *ptr = &arr[-1]` invokes undefined behaviour? Is this true? What does the standard say?
#2: Post edited
- I have heard that it is undefined behaviour to make a pointer point outside boundaries of an array even without dereferencing it. Can that really be true? Consider this code:
char arr[10];char *ptr = arr[-1];char c = *ptr;The third line is obviously bad, because it's accessing out of bounds. But I heard something that even the second line invokes undefined behaviour? Is this true? What does the standard say?
- I have heard that it is undefined behaviour to make a pointer point outside boundaries of an array even without dereferencing it. Can that really be true? Consider this code:
- int main(void)
- {
- char arr[10];
- char *ptr = arr[-1];
- char c = *ptr;
- }
- The line `char c = *ptr` is obviously bad, because it's accessing out of bounds. But I heard something that even the second line invokes undefined behaviour? Is this true? What does the standard say?
#1: Initial revision
Is it undefined behaviour to just make a pointer point outside boundaries of an array without dereferencing it?
I have heard that it is undefined behaviour to make a pointer point outside boundaries of an array even without dereferencing it. Can that really be true? Consider this code: char arr[10]; char *ptr = arr[-1]; char c = *ptr; The third line is obviously bad, because it's accessing out of bounds. But I heard something that even the second line invokes undefined behaviour? Is this true? What does the standard say?