Can I tab[-1] ?

G

glen herrmannsfeldt

Keith Thompson said:
It's a weak suggestion at best:
Each complex type has the same representation and alignment
requirements as an array type containing exactly two elements
of the corresponding real type; the first element is equal to
the real part, and the second element to the imaginary part,
of the complex number.

I suppose, but in the case of SSE it makes some sense. That is,
you might want to process an array multiple elements at a time,
and that is easier, on some machines, if aligned on a larger
boundary.

Also, for larger arrays you might want them page aligned, where
that would be rare for scalars.
The fact that it refers to the alignment requirements of the array
type, rather than of the element type, *might* suggest that they
could differ, but I think it was just easier to word it that way.
6.5.3.4p3 (already quoted in this thread) explicitly says they're
the same.
Which I suspect is what you meant, but I wasn't sure.

-- glen
 
S

Shao Miller

Shao Miller said:
On 12/21/2012 12:37, Tim Rentsch wrote:
C11's 6.2.8p4 seems to suggest that possible alignments are really
derived from fundamental types.

It may to you, but it doesn't to me, and I don't think it should
to anyone else.

Well in that case, I'd suggest that N1570's 6.5.3.4p3 is more suggestive:

"The _Alignof operator yields the alignment requirement of its
operand type. The operand is not evaluated and the result is an integer
constant. When applied to an array type, the result is the alignment
requirement of the element type."

So *some* alignments are derived from fundamental types: those of the
fundamental types themselves, and those of arrays of fundamental types
(and, by induction, arrays of arrays of fundamental types, and so
forth).

But a struct or union may legally have an alignment that exceeds the
alignment of any of its members, or of any fundamental type.

Agreed. Perhaps the "factors of the size that are powers of 2" argument
elsethread can provide additional confidence. I never meant to suggest
that extended alignments[N1570:6.2.8p3] were not allowed, but perhaps my
wording was off... Please allow me to retract and substitute:

"C11's 6.2.8p4 seems to suggest that possible alignments are more
expected to derive from fundamental types than to be extended
alignments, since there may be none of the latter."

It suggests no such thing. There may or may not be extended
alignments. The standard says nothing about which possibility is
"more expected".

Yeah, I guess the argument just doesn't work. I'll retract that one
too, then.
I just noticed something interesting. N1570 uses the phrase
"fundamental types" only twice, both times in the context
of alignment (the second occurrence is in Annex J, which is
non-normative). But it never defines the term. I suppose I've
been assuming that it refers to types other than array, structure,
and union types, but we already have a term for those: scalar types.

There's a distinction between "fundamental alignment" and "extended
alignment". As I understand it, the fundamental alignments are the
default alignments of any type (yielded by _Alignof in the absence
of any alignment specifier); the _Alignas keyword can specify either
a fundamental alignment or an extended alignment.

The maximum fundamental alignment is _Alignof (max_align_t).
Note that max_align_t is merely specified to be an object type;
it needn't be scalar.

That is interesting... I wonder if "fundamental" on its own leads to
some text that might allow for a conclusion of what "fundamental type"
means. I thought I'd read such before, but being wrong is a good
learning opportunity. :)
Not sure what you mean by that.

Yeah, it was just about probability. If someone says "you can have X
oranges and 42 apples, where X might be zero," I'd get my apple juice
preparations underway before I'd worry about the orange juice
preparations. In other words, I was talking about a reader's
expectation based on reading the Standard, rather than the Standard
explicitly detailing an expectation the reader ought to have.

But it's probably a silly thing to've typed and expected to make sense
to anyone else, so I retract.

- Shao Miller
 
S

Shao Miller

I suppose, but in the case of SSE it makes some sense. That is,
you might want to process an array multiple elements at a time,
and that is easier, on some machines, if aligned on a larger
boundary.

Fortunately, in C11 one doesn't have to worry about that ever being the
case without explicitly causing it to be the case by using either
'_Alignas' or by using either a user-defined, third-party-defined, or
implementation-defined type. Using the fundamental types or types
derived from them without specifying an extended alignment shouldn't
yield startling results.

I suspect that the majority of existing C programs expect this and I
doubt that startling results to the contrary have been a major plague
all along.
Also, for larger arrays you might want them page aligned, where
that would be rare for scalars.

Before the formal '_Alignas', I only ever saw implementation extensions
to allow for this. I've never read implementation documentation which
said something along the lines of:

"Special case: Because the size of type int[1024] matches a page
size, whenever such an object is declared or an integer multiple of
sizeof (int[1024]) is used with the memory allocation functions, the
resulting storage will be page-aligned."

Have you or has anyone else? That'd be a real gem. :)

- Shao Miller
 
T

Tim Rentsch

Keith Thompson said:
Tim Rentsch said:
And the writing in 6.2.5 p13 suggests that the alignment of array
types may be different than the alignment of their element types,
but neither of those observations is relevant to the point I was
making.

It's a weak suggestion at best: [snip]

I don't disagree, but here again incidental to what I was
trying to say.
 
F

fir

what way "int (*tab)[N+2]" should be read?

yet one (maybe a little hard) question -

in such case i can decomposite such cryptic statement with two steps

int (*tab)[N+2] ->

int X[N+2}; where X is "(*tab)"

so if X is an array tab is a pointer to such

Can I use such rule of decomposition when reading/writing such cryptic stuff like that?

(fir)
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
474,077
Messages
2,570,567
Members
47,203
Latest member
EmmaSwank1

Latest Threads

Top