3 ms·
It's been a while since I called myself a C expert, but that's not an assignment - it's an initialization. Those are not the same things in C; I think if you g
by NovemberWhiskey 6y ago
It's been a while since I called myself a C expert, but that's not an assignment - it's an initialization.
Those are not the same things in C; I think if you go look at your C standard for the constraints on initialization, they are different from and weaker than those for assignment.
- kllrnohj 6y agoCorrect, the warning is about initialization: "warning: initialization of 'struct Bark ' from incompatible pointer type 'struct Meow '" https://godbolt.org/z/zK45Ys https://godbolt.org/z/zK45Ys
- hvdijk 6y agoYou're correct that initialization is not assignment, but the assignment section is still the relevant place to look: the initialization section says "the same type constraints and conversions as for simple assignment apply". But that isn't obvious and I should have spelled that out.
- NovemberWhiskey 6y agoBut that's in the semantics section; not the constraints section; right?
- hvdijk 6y agoHeh, true. It's pretty clearly meant to mean that the constraints for simple assignment apply as constraints for initialization too, but if you were to argue that the constraints of simple assignment are imported as semantics for initialization, and therefore violations render the behaviour undefined (not requiring any diagnostic), I wouldn't be able to point to anything that shows that to be wrong other than common sense, and common sense can be wrong. The same applies to the return statement, which says "is converted as if by assignment" outside of its "Constraints" section as well.