* Specify alignment for string literal.
@ 2011-10-10 0:34 Kaz Kylheku
2011-10-10 5:11 ` Ian Lance Taylor
0 siblings, 1 reply; 3+ messages in thread
From: Kaz Kylheku @ 2011-10-10 0:34 UTC (permalink / raw)
To: gcc-help
Hi all,
Is there any way to specify the alignment of a literal, with
__attribute__
((align ...))
That is to say:
/* wchar_t is 16 bits and 2 byte aligned on this
platform; I want 4 byte alignment */
wchar_t *foo = L"...";
The attribute has to go on the literal object, not on foo, obviously.
If there is such a feature, it's not obviously documented in the
manual.
I have other ways of solving the problem I'm working on, but this
would be ideal.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Specify alignment for string literal.
2011-10-10 0:34 Specify alignment for string literal Kaz Kylheku
@ 2011-10-10 5:11 ` Ian Lance Taylor
2011-10-10 19:20 ` Kaz Kylheku
0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2011-10-10 5:11 UTC (permalink / raw)
To: Kaz Kylheku; +Cc: gcc-help
Kaz Kylheku <kaz@kylheku.com> writes:
> Is there any way to specify the alignment of a literal, with
> __attribute__
> ((align ...))
Not as such, no.
> That is to say:
>
> /* wchar_t is 16 bits and 2 byte aligned on this
> platform; I want 4 byte alignment */
>
> wchar_t *foo = L"...";
>
> The attribute has to go on the literal object, not on foo, obviously.
Perhaps you could write
static wchar_t foo_str[] __attribute__ ((aligned (4))) = L"...";
wchar_t *foo = foo-str;
Ian
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Specify alignment for string literal.
2011-10-10 5:11 ` Ian Lance Taylor
@ 2011-10-10 19:20 ` Kaz Kylheku
0 siblings, 0 replies; 3+ messages in thread
From: Kaz Kylheku @ 2011-10-10 19:20 UTC (permalink / raw)
To: Ian Lance Taylor; +Cc: gcc-help
On Sun, 09 Oct 2011 22:11:29 -0700, Ian Lance Taylor <iant@google.com>
wrote:
> Kaz Kylheku <kaz@kylheku.com> writes:
>> /* wchar_t is 16 bits and 2 byte aligned on this
>> platform; I want 4 byte alignment */
>>
>> wchar_t *foo = L"...";
>>
>> The attribute has to go on the literal object, not on foo, obviously.
>
> Perhaps you could write
>
> static wchar_t foo_str[] __attribute__ ((aligned (4))) = L"...";
> wchar_t *foo = foo-str;
>
> Ian
Hi Ian,
That's not a bad suggestion. In many cases it could be wrapped
with a macro. E.g.
aligned_literal("abc")
produces a GCC evaluation block:
({ static wchar_t f_o_o[] .... = L"abc"; f_o_o; })
The approach I went with is now documented here:
http://git.savannah.gnu.org/cgit/txr.git/tree/HACKING
In section 2.4.2
I'm adding tag bits to string literals so they can look like
objects in a system of dynamic types.
Turns out we can add a two-bit tag to a pointer even if it
is only two byte aligned, if we can ensure that no two such
objects land into the same four-byte word, and if we have a
way to find the real start of the object after ripping off
the tag.
Since the objects are C strings, it's easy to achieve both
goals with null padding.
Cheers ...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-10-10 19:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-10 0:34 Specify alignment for string literal Kaz Kylheku
2011-10-10 5:11 ` Ian Lance Taylor
2011-10-10 19:20 ` Kaz Kylheku
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).