Deutsch   English   Français   Italiano  
<87zgn65whh.fsf@izac.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder8.news.weretis.net!pasdenom.info!news.izac.org!reader
From: Benoit Izac <use.reply.to@INVALID.ADDRESS>
Newsgroups: fr.comp.lang.python
Subject: Re: =?utf-8?Q?probl=C3=A8me?= avec struct.calcsize qui retourne la
 =?utf-8?Q?m=C3=AAme?= valeur alors qu'un entier non =?utf-8?Q?sign=C3=A9?=
 a =?utf-8?B?w6l0w6kgYWpvdXTDqQ==?= au formatage
Date: Fri, 04 Feb 2022 19:15:38 +0100
Message-ID: <87zgn65whh.fsf@izac.org>
References: <ab88a9d3-a634-40c7-82d1-61bf9c0cc7d2n@googlegroups.com>
Reply-To: benoit.izac@free.fr
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: keg.izac.org;
	logging-data="1985636"; mail-complaints-to="usenet@izac.org"
Bytes: 1877
Lines: 33

Bonjour,

Le 04/02/2022 à 16:29, "pata...@gmail.com" <patatetom@gmail.com> a écrit
dans le message
<ab88a9d3-a634-40c7-82d1-61bf9c0cc7d2n@googlegroups.com> :

> je rencontre un comportement étrange de la part de la fonction
> calcsize du module struct.
>
> voici le problème :
> # 8<-----------
> cd /tmp/
> python --version
> Python 3.10.1
> python -m venv struct.test
> source struct.test/bin/activate
> python -c 'import struct; print(struct.calcsize("4sIQ4I2Q"), 4+4+8+(4*4)+(2*8))'
> 48 48
> python -c 'import struct; print(struct.calcsize("4sIQ5I2Q"), 4+4+8+(5*4)+(2*8))'
> 56 52
> python -c 'import struct; print(struct.calcsize("4sIQ6I2Q"), 4+4+8+(6*4)+(2*8))'
> 56 56
> # 8<-----------
>
> struct.calcsize("4sIQ5I2Q") ne retourne pas 52 comme attendu...
>
> une explication ?

J'imagine que ça vient de là :
<https://en.wikipedia.org/wiki/Data_structure_alignment>, notamment
<https://en.wikipedia.org/wiki/Data_structure_alignment#Typical_alignment_of_C_structs_on_x86>.

-- 
Benoit Izac