Re: [Hampshire] [Slightly OT] Arduino coding help - pointers…

Top Page
Author: Hugo Mills
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] [Slightly OT] Arduino coding help - pointers tostructs

Reply to this message
gpg: failed to create temporary file '/var/lib/lurker/.#lk0x58455100.hantslug.org.uk.18289': Permission denied
gpg: keyblock resource '/var/lib/lurker/pubring.gpg': Permission denied
gpg: Signature made Tue Aug 3 14:30:47 2010 BST
gpg: using DSA key 20ACB3BE515C238D
gpg: Can't check signature: No public key
On Tue, Aug 03, 2010 at 02:19:32PM +0100, Chris Liddell wrote:
> Declarations like your code don't declare variables comprising that
> number of bits, they still are still the size of the base type (in this
> case unsigned int). All the bit length option does (if supported by the
> compiler) is restrict the maximum value of the field (and sometimes not
> even that - many compilers ignore it completely).
>
> So your structure is not 16 bits long, it's 192 bits long.


Not true, at least with gcc 4.4.4:

hrm@shades:~$ cat <<EOF >foo.c
> #include <stdio.h>
>
> struct received_data {
>     unsigned int start:1;
>     unsigned int address:4;
>     unsigned int command:5;
>     unsigned int flags:4;
>     unsigned int padding:1;
>     unsigned int parity:1;
> };

>
> int main(int argc, char* argv[])
> {
> printf("%d\n", sizeof(struct received_data));
> return 0;
> }
> EOF

hrm@shades:~$ gcc foo.c
hrm@shades:~$ ./a.out
4

Hugo.

-- 
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
   --- Nothing wrong with being written in Perl... Some of my best ---   
                      friends are written in Perl.