Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.lang.python > #3744

Re: problème avec struct.calcsize qui retourne la même valeur alors qu'un entier non signé a été ajouté au formatage

Path csiph.com!pasdenom.info!news.izac.org!reader
From Benoit Izac <use.reply.to@INVALID.ADDRESS>
Newsgroups fr.comp.lang.python
Subject Re: problème avec struct.calcsize qui retourne la même valeur alors qu'un entier non signé a été ajouté au formatage
Date Fri, 04 Feb 2022 19:15:38 +0100
Message-ID <87zgn65whh.fsf@izac.org> (permalink)
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"
Xref csiph.com fr.comp.lang.python:3744

Show key headers only | View raw


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

Back to fr.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

problème avec struct.calcsize qui retourne la même valeur alors qu'un entier non signé a été ajouté au formatage "pata...@gmail.com" <patatetom@gmail.com> - 2022-02-04 07:29 -0800
  Re: problème avec struct.calcsize qui retourne la même valeur alors qu'un entier non signé a été ajouté au formatage Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2022-02-04 19:15 +0100
    Re: problème avec struct.calcsize qui retourne la même valeur alors qu'un entier non signé a été ajouté au formatage Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2022-02-04 22:55 +0100
      Re: problème avec struct.calcsize qui retourne la même valeur alors qu'un entier non signé a été ajouté au formatage "pata...@gmail.com" <patatetom@gmail.com> - 2022-02-05 04:20 -0800

csiph-web