This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: struct.unpack of Bool
Type: behavior Stage: resolved
Components: ctypes Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: struct.unpack('?', '\x02') returns (False,) on Mac OSX
View: 22012
Assigned To: Nosy List: Weihong Guan, meador.inge, serhiy.storchaka
Priority: normal Keywords:

Created on 2016-10-06 13:14 by Weihong Guan, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Screen Shot 2016-10-06 at 20.59.43.png Weihong Guan, 2016-10-06 13:14
Messages (3)
msg278192 - (view) Author: Weihong Guan (Weihong Guan) Date: 2016-10-06 13:14
According to the doc:

For the '?' format character, the return value is either True or False. When packing, the truth value of the argument object is used. Either 0 or 1 in the native or standard bool representation will be packed, and any non-zero value will be True when unpacking.

But it behaves more like & 1 operation. so False for even value, and True for odd value.

unpack fmt '?H' should reqiure buff of length 3, same as 'H?', not 4.
msg278195 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-10-06 14:40
Maybe this is a duplicate of issue22012.
msg278236 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2016-10-07 12:21
Looks like a dup to me.
History
Date User Action Args
2022-04-11 14:58:37adminsetgithub: 72563
2016-10-07 17:12:39berker.peksagsetstatus: open -> closed
superseder: struct.unpack('?', '\x02') returns (False,) on Mac OSX
resolution: duplicate
stage: resolved
2016-10-07 12:21:59meador.ingesetnosy: + meador.inge
messages: + msg278236
2016-10-06 14:40:34serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg278195
2016-10-06 13:14:23Weihong Guancreate