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.
Activity for chris-barryâ€
Type | On... | Excerpt | Status | Date |
---|---|---|---|---|
Edit | Post #277331 |
Post edited: Having given more consideration to the implications of the question, I have completely rewritten my answer. |
— | over 4 years ago |
Comment | Post #277331 |
@lundin Interestingly, _6.5.6/8_ places restrictions on pointer arithmetic. As a not-too-contrived-example, imagine a user selects from a list numbered from one up. This is used to index a zero-based array. A simple approach would be to create a pointer to element -1 then add the user's selection to ... (more) |
— | over 4 years ago |
Comment | Post #277331 |
@lundin True. The only way to determine that something is undefined is to look at the definition. Your example, however, is inappropriate as it attempts to dereference an out-of-bounds element and the OP says: "even without dereferencing it". (more) |
— | over 4 years ago |
Comment | Post #277331 |
@klutt No. I am saying that it will not compile because you ar trying to assign a value of type char to a variable of type pointer. However, even if the types were made to match (by making arr an array of pointers to char, rather than an array of char) your code sample would not illustrate your quest... (more) |
— | over 4 years ago |
Edit | Post #277331 | Initial revision | — | over 4 years ago |
Answer | — |
A: Is it undefined behaviour to just make a pointer point outside boundaries of an array without dereferencing it? When a compiler encounters the statements ``` char arr[10]; char ptr = &arr[-1] ``` there are three things that it could reasonably do: 1. It can raise an error. 2. It can compile the statements and raise a warning. 3. It can compile the statemnts silently. I think that, in cases... (more) |
— | over 4 years ago |