Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.c Subject: Re: A glitch regarding the usual malloc() idiom Date: Thu, 28 Jul 2016 14:51:21 +0100 Organization: A noiseless patient Spider Lines: 40 Message-ID: <87zip1yip2.fsf@bsb.me.uk> References: <5793c8e5.2941812@news.xs4all.nl> <87oa5n97rz.fsf@bsb.me.uk> <87wpkar54r.fsf@bsb.me.uk> <87d1m1r99c.fsf@bsb.me.uk> <871t2hqn06.fsf@bsb.me.uk> <87fuqwp5fc.fsf@bsb.me.uk> <2c152373-28b9-49dc-b221-d24dcb9ee08c@googlegroups.com> <8760rrf6q8.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="30829"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/BwjINWPTTTyyPxc1JYbSwacGQcQ8KH5Q=" Cancel-Lock: sha1:LODD5zZs3TWfkqVZwK9V19TQcgU= sha1:3Fz7XtXFcBvvsMt1Vy+p20DjnIc= X-BSB-Auth: 1.14e4a68620d01ddbf510.20160728145121BST.87zip1yip2.fsf@bsb.me.uk Xref: csiph.com comp.lang.c:91231 BartC writes: > On 27/07/2016 16:20, Ben Bacarisse wrote: >> David Brown writes: >> >>> On 27/07/16 14:34, Richard Heathfield wrote: >>>> On 27/07/16 11:21, BartC wrote: >>> >>>> >>>>> (BTW why is it only C that is obsessed with padding bits? They don't >>>>> seem to crop up with any other language. Not even assembly.) >>>> >>> >>> Assembly can have padding bits too - it's just assembly on the >>> processors /you/ are familiar with that don't have them. To be fair, >>> few modern cpus need any sort of padding unless you are trying to use >>> bitfields. But they do turn up in odd processor architectures, >>> including some mainframes or older machines. So C allows the >>> possibility of padding bits for much the same reasons it allows signed >>> integers in formats other than two's complement. >> >> There's another more direct use of padding bits: _Bool. In most C >> implementations _Bool has one value bit and 7 padding bits. > > Are the really padding bits, or does it just restrict the value that > can be stored in an 8-bit type to 0 or 1 instead of 0 to 255? The bits in an integer type's representation are either a sign bit, values bits or padding bits. > Because I could easily store data in those extra 7 bits in all six C > compilers I tried (by casting _Bool* to char*). Yes, that's common. Exactly what happens then is then up to the implementation, but it's got carte blanche since almost everything to do with padding bits is undefined. -- Ben.