Optional slice declaration

Thanks! I finally got it! Had to stare at it for a while and read your respond like 100 times but I get it now.

In theory you could read this yourself, left to right, and it should make sense:

variable x is an array with 2 elements, each of them is an optional (?) pointer (*) to an array of 2 elements, each of them being a u8; x is left as undefined

5 Likes

Of course it can, like when I use it in a condition. But is, for example, printing it on the screen an undefined behaviour (as understood by clang/llvm and gcc)?

Accessing undefined memory for anything other than setting it to a defined value is a BIG code smell.

Yes, it’s undefined behaviour. Setting something to undefined is used by the compiler to generate optimizations.

Hey everyone - this help thread is marked as solved. I’d encourage you to open up a new thread about how and when to use the keyword undefined and continue this discussion there.

Yes, this thread is marked as solved but IMHO the solution is unsatisfactory. Where can I vote solution up or down?

Thanks for the reply. Can you articulate why you think the solution is unsatisfactory? I’ll unmark it if you can provide an explanation for why this doesn’t satisfy the question.