C negative array index

this is my struct :

struct Node {
    struct Node* data;
    struct Node* links[4];
}

assuming there is no padding, does Node->links[-1] guaranteed to be pointing on Node::data ?

Answers


No guarantee; this is undefined behaviour:

  • Compiler-dependent structure padding
  • Standard only defines array indexing between 0 and length (inclusive)
  • Possible strict-aliasing violation

In practice, it's quite possible that you will end up pointing at data, but any attempts to access it will result in UB.


Need Your Help

Best practices for maintaining shared hosting websites with ASP.NET and SQL Server?

asp.net visual-studio shared-hosting

I've been doing PHP/MySQL websites with shared hosting providers for the last couple years. The day-to-day process is basically:

View Multiple Screen Support

android view bitmap screen

I know there's a lot of info out there about this topic, but I still kinda confused. I made a class view for an android app, that works with bitmaps and text.