Array operand of _Alignof

151 views
Skip to first unread message

Keith Thompson

unread,
Mar 28, 2013, 2:13:57 PM3/28/13
to
N1570 (C11) 6.3.2.1p3 says:

Except when it is the operand of the sizeof operator, the _Alignof
operator, or the unary & operator, or is a string literal used to
initialize an array, an expression that has type ``array of type''
is converted to an expression with type ``pointer to type'' that
points to the initial element of the array object and is not an
lvalue.

This adds one more exception to the rule for when arrays decay, or don't
decay, to pointers.

But the grammar for a "unary-expression" is, in part:

unary-expression:
[...]
sizeof unary-expression
sizeof ( type-name )
_Alignof ( type-name )

Unlike sizeof, there is no form of _Alignof that takes an expression as
an operand. Which means that the new exception in 6.3.2.1p3 can never
apply.

This was probably a simple oversight. Perhaps the committee intended at
one point to permit `_Alignof unary-expression`.

Conclusion: In spite of the extra wording in 6.3.2.1p3, the C11 rules
for when an array expression decays to a pointer are still exactly the
same as they were in C99 and C90.

A related issue: Why was `_Alignof unary-expression` excluded?

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

lawrenc...@siemens.com

unread,
Mar 31, 2013, 8:02:06 PM3/31/13
to
Keith Thompson <ks...@mib.org> wrote:
> N1570 (C11) 6.3.2.1p3 says:
>
> Except when it is the operand of the sizeof operator, the _Alignof
> operator, or the unary & operator, or is a string literal used to
> initialize an array, an expression that has type ``array of type''
> is converted to an expression with type ``pointer to type'' that
> points to the initial element of the array object and is not an
> lvalue.
>
> This adds one more exception to the rule for when arrays decay, or don't
> decay, to pointers.

Adding _Alignof was a screwup by yours truly that was fixed in the final
version.

> A related issue: Why was `_Alignof unary-expression` excluded?

A good question that I don't know the answer to.
--
Larry Jones

I don't NEED to compromise my principles, because they don't have
the slightest bearing on what happens to me anyway. -- Calvin

Keith Thompson

unread,
Mar 31, 2013, 11:23:14 PM3/31/13
to
lawrenc...@siemens.com writes:
> Keith Thompson <ks...@mib.org> wrote:
>> N1570 (C11) 6.3.2.1p3 says:
>>
>> Except when it is the operand of the sizeof operator, the _Alignof
>> operator, or the unary & operator, or is a string literal used to
>> initialize an array, an expression that has type ``array of type''
>> is converted to an expression with type ``pointer to type'' that
>> points to the initial element of the array object and is not an
>> lvalue.
>>
>> This adds one more exception to the rule for when arrays decay, or don't
>> decay, to pointers.
>
> Adding _Alignof was a screwup by yours truly that was fixed in the final
> version.

So it was. I hadn't known there were any differences between N1570 and
the final standard.

>> A related issue: Why was `_Alignof unary-expression` excluded?
>
> A good question that I don't know the answer to.

--

lawrenc...@siemens.com

unread,
Apr 5, 2013, 2:07:23 PM4/5/13
to
Keith Thompson <ks...@mib.org> wrote:
>
> So it was. I hadn't known there were any differences between N1570 and
> the final standard.

There are a number of them, but most are just minor editorial tweaks,
changes to boilerplate text, and shuffling things around to keep the
powers that be happy. The biggest change was removing _Alignof from a
bunch of places it shouldn't have been added (based on the erroneous
notion that it takes either a type or an expression like sizeof does
when it really only takes a type): 6.3.2.1p2, p3, p4, fn. 65; and 6.7.1
fn. 121.
--
Larry Jones

What a waste to be going to school on a morning like this. -- Calvin

Shao Miller

unread,
Apr 6, 2013, 8:25:01 PM4/6/13
to
On 3/28/2013 14:13, Keith Thompson wrote:
>
> A related issue: Why was `_Alignof unary-expression` excluded?
>

Also: Is there a reason why it should not be included, in the future?

--
- Shao Miller
--
"Thank you for the kind words; those are the kind of words I like to hear.

Cheerily," -- Richard Harter

William Ahern

unread,
Apr 8, 2013, 12:08:06 AM4/8/13
to
Shao Miller <sha0....@gmail.com> wrote:
> On 3/28/2013 14:13, Keith Thompson wrote:
> >
> > A related issue: Why was `_Alignof unary-expression` excluded?
> >

> Also: Is there a reason why it should not be included, in the future?

Or just add typeof and solve these problems once-and-for-all :)

Perhaps the hesitations with typeof were the same ones which precluded
_Alignof taking expressions--presumably, too much effort on the part of
vendors not already supporting it.

erkina...@gmail.com

unread,
Apr 12, 2013, 5:03:04 PM4/12/13
to
8 Nisan 2013 Pazartesi 07:08:06 UTC+3 tarihinde William Ahern yazdı:
Adding of type of in C15(estimated) will require standardization of type identifiers, which done in C++ standard (typeid) and in C compilers implemented as C++ compiler port.

After that, we can use type identifier expressions everywhere and do more generic programing.
Reply all
Reply to author
Forward
0 new messages