www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2012/07/28/07:00:19

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: =?ISO-8859-15?Q?Hans-Bernhard_Br=F6ker?= <HBBroeker AT t-online DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Upgrading from a bad C compiler
Date: Sat, 28 Jul 2012 12:41:01 +0200
Lines: 39
Message-ID: <a7htthFse5U1@mid.dfncis.de>
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>
Mime-Version: 1.0
X-Trace: news.dfncis.de /PRQJm4CWi2qUBQ51Civxw+LFUDAcehnahEsZ5UjqqL+FFLAoL4mtnlsxIZYk0GhBc8MeqB+lV
Cancel-Lock: sha1:uEvXYL4P0IST6/CaPkdbghK2qE4=
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:13.0) Gecko/20120604 Thunderbird/13.0
In-Reply-To: <juuseq$j7b$1@speranza.aioe.org>
Bytes: 2790
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
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

On 27.07.2012 22:09, Rod Pemberton wrote:

> I didn't know that, but I avoid sizeof().

Frankly, that's a pretty silly position.

> One could definately argue C shouldn't "know" anything about the padding,
> i.e., it can be argued that padding is outside of C's "sphere of knowledge".

Whether or not that argument can possibly make sense depends on what you 
mean by "C" here: the C source code, the C translation tools, or some 
combination of the two?

Yes, C source code must not know such things all by itself.  But the C 
tools obviously must know (or they couldn't support structs at all). 
But sometimes the C source needs a way to inquire the info from the C 
tools, e.g. to dynamically allocate (arrays of) structs.   The sizeof() 
operator is this way.

> Either way, I see sizeof() leading to problems.

You got that backwards.  sizeof() is what solves those problems.

The actual problem is with people who believe they know better than the 
C compiler what the actual size of a particular data structure must be, 
and therefore come here (and elsewhere) to complain that their 
compiler's sizeof() were buggy.

> There will be those who want to know the exact underlying size of the
> aligned and padded struct so they can allocate space for more aligned and
> padded structs correctly.

Those people have understood what sizeof() is for.

> There will also be those who only want to know only the size of the struct's
> C components so that when they copy the structs C elements to an array or
> other object they don't have extra space included, etc.

Such people have to sum the sizes of individual elements themselves.

- Raw text -


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