Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Can I tab[-1] ?

Reply
Thread Tools

Can I tab[-1] ?

 
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      12-22-2012
Keith Thompson <(E-Mail Removed)> wrote:
> Tim Rentsch <(E-Mail Removed)> writes:
> [...]
>> 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:


> 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
 
Reply With Quote
 
 
 
 
Shao Miller
Guest
Posts: n/a
 
      12-22-2012
On 12/22/2012 06:13, Keith Thompson wrote:
> Shao Miller <(E-Mail Removed)> writes:
>> On 12/21/2012 21:32, Keith Thompson wrote:
>>> Shao Miller <(E-Mail Removed)> writes:
>>>> On 12/21/2012 12:37, Tim Rentsch wrote:
>>>>> Shao Miller <(E-Mail Removed)> writes:

> [...]
>>>>>> 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.

>> I guess it's a Bayesian argument?

>
> 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
 
Reply With Quote
 
 
 
 
Shao Miller
Guest
Posts: n/a
 
      12-22-2012
On 12/22/2012 07:51, glen herrmannsfeldt wrote:
> Keith Thompson <(E-Mail Removed)> wrote:
>> Tim Rentsch <(E-Mail Removed)> writes:
>> [...]
>>> 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:

>
>> 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.
>


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
 
Reply With Quote
 
Tim Rentsch
Guest
Posts: n/a
 
      12-22-2012
Keith Thompson <(E-Mail Removed)> writes:

> Tim Rentsch <(E-Mail Removed)> writes:
> [...]
>> 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.
 
Reply With Quote
 
fir
Guest
Posts: n/a
 
      12-23-2012
>
> 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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Groovy be used in an applet and/or can it generate the Java bytecodes that then can be used in an applet? Casey Hawthorne Java 1 03-18-2009 12:56 AM
Word Docs Won't Open, Can't Be E-Mailed, Can't Be Deleted, Can't Be Copied, Etc. Martin Computer Support 16 02-24-2009 07:35 PM
Wireless can get internet but can't see network -- can when wired 02befree Computer Support 0 12-24-2007 09:10 PM
SOLVED - can't open file in windows media player / WMP. But can in VLC - video LAN .. Now can in WMP jameshanley39@yahoo.co.uk Computer Information 2 09-19-2007 02:53 AM
Windows can see mapped drives, but applications can't? =?Utf-8?B?RGFuaWVsIEVpY2hvcm4=?= Wireless Networking 3 11-18-2004 11:03 PM



Advertisments