C
CBFalconer
pete said:Because vp holds an address which is not aligned for type int.
No. Because the conversion pointertype->void*type->pointertype is
only valid when the two pointertypes are identical.
pete said:Because vp holds an address which is not aligned for type int.
No. Because the conversion pointertype->void*type->pointertype is
only valid when the two pointertypes are identical.
Dan Pop said:In said:N869
6.3.2.3 Pointers
[#7] A pointer to an object or incomplete type may be
converted to a pointer to a different object or incomplete
type. If the resulting pointer is not correctly aligned
for the pointed-to type, the behavior is undefined.
N869
6.3.2.3 Pointers
[#1] A pointer to void may be converted to or from a pointer
to any incomplete or object type. A pointer to any
incomplete or object type may be converted to a pointer to
void and back again; the result shall compare equal to the
original pointer.
1. Why do you think that #7 does not apply this time?
Because the standard says so: character and void pointer values have
no alignment restrictions. Therefore, when converting something to
pointer to void, the resulting value is, by definition, correctly aligned.
It does. But #7 applies too.
[ ^^^^^^^^ strictly, it talks about resulting pointer,There is no contradiction between the two.
#1 says that you can do the conversion and #7 says what happens if the
original pointer value was not properly aligned for the type of the result
of the conversion.
The rest of the standard.
Unfortunately, the standard is very poorly
written as a reference document: you can't only read the paragraph(s)
of immediate interest and expect to get a complete picture of the issue.
In said:Would you please be so kind to give some pointers for an example.
In said:I took the first plausible definition I found. C++ is not topical here,
but C++ shares many ideas with C. I thought the definition in above
document was not C++ specific. Anonymous structures aren't topical
here either. I was casually interested, since someone mentioned them.
I think the above example you provided is called "unnamed structure".
Read the whole standard. If you still need the pointers, I will give
them to you.
If you want to lose your time by reading only random paragraphs, that's
fine, but this is not a reason for wasting my time, too.
In said:I don't understand why to answer the simple question: if #7 is applicable
for (int*)->(void*) conversion, I have to read the whole Standard.
It requires only basic intelligence and comprehension.
That's the common and sensible implementation, but not required. It isWrong. Both the struct and union have the same
alignment as double. A struct's alignment is
the same as the strictest (widest) alignment
of any of its members, including nested aggregates.
Same rules apply for union. The alignment is that
of the strictest alignment of any of its members,
including nested aggregates (other unions or
structs).
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.