public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kaz Kylheku <kaz@kylheku.com>
To: Ian Lance Taylor <iant@google.com>
Cc: <gcc-help@gcc.gnu.org>
Subject: Re: Specify alignment for string literal.
Date: Mon, 10 Oct 2011 19:20:00 -0000	[thread overview]
Message-ID: <0d8e7a1845169f6b7943ddb55ac24a94@127.0.0.1> (raw)
In-Reply-To: <mcrty7h77ni.fsf@coign.corp.google.com>


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

      reply	other threads:[~2011-10-10 19:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-10  0:34 Kaz Kylheku
2011-10-10  5:11 ` Ian Lance Taylor
2011-10-10 19:20   ` Kaz Kylheku [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0d8e7a1845169f6b7943ddb55ac24a94@127.0.0.1 \
    --to=kaz@kylheku.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=iant@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).