This is mainly a followup to Should definition and declaration match?
Question
Is it legal in C to have (for example) int a[10];
in one compilation unit and extern int a[4];
in another one ?
(You can find a working example in my answer to ref'd question)
Disclaimers :
- I know it is dangerous and would not do it in production code
- I know that if you have both in same compilation unit (typically through inclusion of a .h in the file containing the definition) compilers detects an error
- I have already read Jonathan Leffler' excellent answer to How do I use extern to share variables between source files? but could not find the answer to this specific point there - even if Jonathan showed even worse usages ...
Even if different comments in referenced post spotted that as UB, I could not find any authoritative reference for it. So I would say that there is no UB here and that second compilation unit will have access to the beginning of the array, but I would really like a confirmation - or instead a reference about why it is UB