delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2012/07/30/12:39:53

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
X-Recipient: djgpp AT delorie DOT com
Date: Mon, 30 Jul 2012 19:39:50 +0300
From: Eli Zaretskii <eliz AT gnu DOT org>
Subject: Re: Upgrading from a bad C compiler
In-reply-to: <jv6ad7$vqc$1@speranza.aioe.org>
X-012-Sender: halo1 AT inter DOT net DOT il
To: djgpp AT delorie DOT com
Message-id: <83ipd5fbjd.fsf@gnu.org>
References: <17d4b525-2c31-4c20-b3c5-a7118343e9a5 AT googlegroups DOT com> <jucp01$p35$1 AT speranza DOT aioe DOT org> <b1f8c389-45f4-43e4-9056-62fc50fc9462 AT googlegroups DOT com> <juh7c1$7hk$1 AT speranza DOT aioe DOT org> <3331145d-900b-4bef-8ad0-f533f0b4a17b AT googlegroups DOT com> <juuseq$j7b$1 AT speranza DOT aioe DOT org> <a7htthFse5U1 AT mid DOT dfncis DOT de> <jv1ect$iv$1 AT speranza DOT aioe DOT org> <83lii3hd5r DOT fsf AT gnu DOT org> <jv6ad7$vqc$1 AT speranza DOT aioe DOT org>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> From: "Rod Pemberton" <do_not_have AT notemailnot DOT cmm>
> Date: Mon, 30 Jul 2012 11:51:01 -0400
> 
> > > But, my usage of it is minimal, only where absolutely needed.
> >
> > This can be said about every feature of every programming language --
> > they should be used only when necessary.
> 
> Your interpretation of my statement seems to lack restraint and avoidance.
> I don't see "absolutely needed" and "necessary" as equivalent.  "Necessary"
> could mean whatever was coded by the programmer.

You are nitpicking.  These are synonyms.  At least that's what I meant
them to be.

> I.e., it may be
> "necessary" to use the size of an object, but sizeof() may not be
> "absolutely needed" to do that.  E.g., the object's size might be known from
> it's declaration, such as for an array, or via strlen() which can be used
> for non-strings, or use of the "C struct hack" or from address calculations
> on "dummy" structure elements, or fscanf() etc.  Following your description,
> one would use sizeof() because it's "necessary" to get the size.

No need to assume that I have silly thoughts like that.

> No, I've made no claims about what sizeof() should or shouldn't return.

You said it "works" (i.e. the results are evident in advance) for
primitive data types.  My point was that even that is not true.

> Although, I do have a preference.  I was talking about possible expectations
> by others.  I.e., what does 'sizeof()' mean to someone using it?  What do
> they expect to get from it?  What 'size of' is expected to be returned?

It is expected to return the size that its argument takes in storage.

> You do realize that C could've added padding even to simple types.  Yes?

Isn't that what my example with long double demonstrates?

> > Now try the sample program at the end of this message.
> 
> I ran some other code.
> 
> OpenWatcom returns 8 ...
> 
> OpenWatcom
> long double 8
> double 8
> float 4

An implementation is allowed to have long double be identical to
double.  That's what Watcom does, evidently.

> DJGPP returns 12.
> 
> DJGPP
> long double 12
> double 8
> float 4
> 
> Can I get 10 if I use '#pragma pack(push,1)' ?

No, you can't.

> If DJGPP is storing a mem80 for a 'long double' and 10 can never be
> returned by sizeof(), then DJGPP's sizeof() is broken.

No, it isn't.  It's your interpretation of sizeof that's broken.

> Or, if the two extra bytes are to store something relevant for a 'long
> double', say x87's control word

No, they are for the proper alignment of array elements in an array of
long double.  Accessing an element that is not aligned on a 4-byte
boundary means severe runtime penalty.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019