Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: [comp.lang.c.moderated] valid "struct hack" in C89

16 views
Skip to first unread message

Clive D. W. Feather

unread,
Dec 25, 2009, 7:24:31 PM12/25/09
to
[Alignment of a given type]
> However, a true language-level construct would be better than
> either workaround.

I have a vague memory that we discussed this idea during development of
the C99 standard, but rejected it. However, I can't recall why (though
the most likely reason is lack of utility).

--
Clive D.W. Feather | Home: <cl...@davros.org>
Mobile: +44 7973 377646 | Web: <http://www.davros.org>
Please reply to the Reply-To address, which is: <cl...@davros.org>
--
comp.lang.c.moderated - moderation address: cl...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.

Seebs

unread,
Dec 25, 2009, 8:35:15 PM12/25/09
to
On 2009-12-26, Clive D. W. Feather <cl...@davros.org> wrote:
> I have a vague memory that we discussed this idea during development of
> the C99 standard, but rejected it. However, I can't recall why (though
> the most likely reason is lack of utility).

My vague recollection was that we couldn't think of a system where
sizeof(type) wouldn't be Good Enough. So, lack of marginal utility.

I could be totally wrong, my memory's not awesome.

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

Keith Thompson

unread,
Dec 26, 2009, 1:43:26 AM12/26/09
to
Seebs <usenet...@seebs.net> writes:
> On 2009-12-26, Clive D. W. Feather <cl...@davros.org> wrote:
>> I have a vague memory that we discussed this idea during development of
>> the C99 standard, but rejected it. However, I can't recall why (though
>> the most likely reason is lack of utility).
>
> My vague recollection was that we couldn't think of a system where
> sizeof(type) wouldn't be Good Enough. So, lack of marginal utility.
>
> I could be totally wrong, my memory's not awesome.

sizeof(type) would be good enough for scalar types, but for large
structs it would be useful to be able to determine that, say, a
1024-byte struct only needs 4-byte alignment.

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

Clive D. W. Feather

unread,
Dec 26, 2009, 3:49:51 PM12/26/09
to
In message <clcm-2009...@plethora.net>, Keith Thompson
<ks...@mib.org> wrote:
>>> I have a vague memory that we discussed this idea during development of
>>> the C99 standard, but rejected it. However, I can't recall why (though
>>> the most likely reason is lack of utility).
[...]

>sizeof(type) would be good enough for scalar types, but for large
>structs it would be useful to be able to determine that, say, a
>1024-byte struct only needs 4-byte alignment.

Why would it?

In other words, suppose that the Standard included a pseudo-function:

size_t alignmentof (type t);

What could you portably do with it that you can't portably do without
it?

--
Clive D.W. Feather | Home: <cl...@davros.org>
Mobile: +44 7973 377646 | Web: <http://www.davros.org>
Please reply to the Reply-To address, which is: <cl...@davros.org>

Seebs

unread,
Dec 26, 2009, 4:06:54 PM12/26/09
to
On 2009-12-26, Clive D. W. Feather <cl...@davros.org> wrote:
> In other words, suppose that the Standard included a pseudo-function:
>
> size_t alignmentof (type t);
>
> What could you portably do with it that you can't portably do without
> it?

Possibly implement your own special-purpose memory allocation routine which
works within larger blocks but has performance characteristics suited to
a particular environment or usage -- in which you might want to know, having
stashed a (foo_t) at the beginning of a block, how much padding you need
between it and a subsequent (bar_t).

I can't imagine there's much overlap between the set of people who think
they need to do this, and the set of people who can actually outperform
a modern malloc implementation, but perhaps there's some.

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

Keith Thompson

unread,
Dec 26, 2009, 5:29:42 PM12/26/09
to
Seebs <usenet...@seebs.net> writes:
> On 2009-12-26, Clive D. W. Feather <cl...@davros.org> wrote:
>> In other words, suppose that the Standard included a pseudo-function:
>>
>> size_t alignmentof (type t);
>>
>> What could you portably do with it that you can't portably do without
>> it?
>
> Possibly implement your own special-purpose memory allocation routine which
> works within larger blocks but has performance characteristics suited to
> a particular environment or usage -- in which you might want to know, having
> stashed a (foo_t) at the beginning of a block, how much padding you need
> between it and a subsequent (bar_t).
>
> I can't imagine there's much overlap between the set of people who think
> they need to do this, and the set of people who can actually outperform
> a modern malloc implementation, but perhaps there's some.

Well, there are the people who actually *write* modern malloc
implementations. They can certainly use implementation-specific
tricks, but surely adding something like alignmentof to the language
would make their jobs easier.

Which is probably at least part of the reason that the "alignof"
keyword is being added to C201X; see n1425.pdf.

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

0 new messages