Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: C Macro define contain symbol # |
| Date | 2011-09-13 20:19 -0700 |
| Organization | None to speak of |
| Message-ID | <ln7h5bbyjw.fsf@nuthaus.mib.org> (permalink) |
| References | <c351b443-5581-4db0-8760-3f117eebce77@x32g2000prf.googlegroups.com> <j4ngch$oqb$1@dont-email.me> <92iu67h2ki8sgm1u9bvpfk8qu3hfremcoo@4ax.com> <lnbouob9av.fsf@nuthaus.mib.org> <j4oqet$8pk$1@dont-email.me> |
"BartC" <bc@freeuk.com> writes:
> "Keith Thompson" <kst-u@mib.org> wrote in message
> news:lnbouob9av.fsf@nuthaus.mib.org...
>> Roberto Waltman <usenet@rwaltman.com> writes:
>
>>> Even Pascal had packed records.
>>
>> Yes, but Pascal packed records, as I recall, are merely a hint to the
>> compiler that space should be minimized. They're not necessarily
>> suitable for matching a specific externally imposed layout.
>>
>> One example of a problem that would have to be solved:
>>
>> struct foo {
>> char c;
>> int i;
>> };
>> #pragma pack(struct foo) /* or whatever the syntax is */
>>
>> void some_func(int *p);
>>
>> struct foo obj;
>> some_func(&obj.i);
>
>> I've worked on systems where an int* cannot contain an address that
>> isn't word-aligned. Do you forbid taking the address of a member of a
>> packed struct?
>
> Suppose *all* addresses have to be word-aligned (which used to be quite
> common). Then you'd have the same problem with:
>
> struct foo {
> char c[2];
> int i;
> };
>
> and trying to take the address of c[1] (or even just trying to access it).
> (This assumes you don't just make char and int the same size.)
You're making assumptions that make a conforming C implementation
impossible, unless a "word" is 1 byte. c[1] must have a valid address.
That address is of type char*, which may or may not have the same
representation as an int*. On the system I was referring to, a char*
can old a byte-aligned address, but an int* can only hold a word-aligned
address.
(The system was the Cray T90. The word size was 64 bits, and there was
no hardware support for byte addressing. Byte addresses were
implemented in software by storing an offset in the high-order 3 bits of
a 64-bit pointer.)
> The Pascal 'packed' directive perhaps *was* an instructive to pack things
> more tightly than hardware considerations would normally dictate.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C Macro define contain symbol # Wang WolfLouis <wolflouiswang@gmail.com> - 2011-09-13 02:47 -0700
Re: C Macro define contain symbol # Noob <root@127.0.0.1> - 2011-09-13 13:14 +0200
Re: C Macro define contain symbol # Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-13 07:55 -0400
Re: C Macro define contain symbol # Roberto Waltman <usenet@rwaltman.com> - 2011-09-13 08:24 -0400
Re: C Macro define contain symbol # Keith Thompson <kst-u@mib.org> - 2011-09-13 11:12 -0700
Re: C Macro define contain symbol # Keith Thompson <kst-u@mib.org> - 2011-09-13 20:19 -0700
Re: C Macro define contain symbol # Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-09-16 00:43 +0300
Re: C Macro define contain symbol # Keith Thompson <kst-u@mib.org> - 2011-09-15 18:34 -0700
Re: C Macro define contain symbol # Richard Damon <news.x.richarddamon@xoxy.net> - 2011-09-13 22:51 -0400
Re: C Macro define contain symbol # Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-14 12:16 +0100
Re: C Macro define contain symbol # tom st denis <tom@iahu.ca> - 2011-09-13 11:20 -0700
Re: C Macro define contain symbol # Ian Collins <ian-news@hotmail.com> - 2011-09-14 07:55 +1200
Re: C Macro define contain symbol # Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-14 07:58 -0400
Re: C Macro define contain symbol # Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-09-14 14:54 +0000
Re: C Macro define contain symbol # Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-09-16 00:34 +0300
Re: C Macro define contain symbol # Nobody <nobody@nowhere.com> - 2011-09-16 12:07 +0100
Re: C Macro define contain symbol # "BartC" <bc@freeuk.com> - 2011-09-13 13:50 +0100
Re: C Macro define contain symbol # James Kuyper <jameskuyper@verizon.net> - 2011-09-13 08:59 -0400
Re: C Macro define contain symbol # Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-09-14 15:02 +0000
Re: C Macro define contain symbol # Kenneth Brody <kenbrody@spamcop.net> - 2011-09-13 16:54 -0400
csiph-web