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


Groups > sci.electronics.design > #400092 > unrolled thread

Union of bitfields and larger type on ARM

Started bybitrex <bitrex@de.lete.earthlink.net>
First post2016-02-23 14:17 -0500
Last post2016-02-27 14:37 +0100
Articles 20 on this page of 35 — 13 participants

Back to article view | Back to sci.electronics.design


Contents

  Union of bitfields and larger type on ARM bitrex <bitrex@de.lete.earthlink.net> - 2016-02-23 14:17 -0500
    Re: Union of bitfields and larger type on ARM Lasse Langwadt Christensen <langwadt@fonz.dk> - 2016-02-23 11:36 -0800
      Re: Union of bitfields and larger type on ARM John Devereux <john@devereux.me.uk> - 2016-02-23 19:40 +0000
        Re: Union of bitfields and larger type on ARM bitrex <bitrex@de.lete.earthlink.net> - 2016-02-23 14:42 -0500
      Re: Union of bitfields and larger type on ARM bitrex <bitrex@de.lete.earthlink.net> - 2016-02-23 14:46 -0500
        Re: Union of bitfields and larger type on ARM Lasse Langwadt Christensen <langwadt@fonz.dk> - 2016-02-23 12:23 -0800
          Re: Union of bitfields and larger type on ARM bitrex <bitrex@de.lete.earthlink.net> - 2016-02-23 16:50 -0500
            Re: Union of bitfields and larger type on ARM Lasse Langwadt Christensen <langwadt@fonz.dk> - 2016-02-23 14:11 -0800
              Re: Union of bitfields and larger type on ARM bitrex <bitrex@de.lete.earthlink.net> - 2016-02-23 17:16 -0500
                Re: Union of bitfields and larger type on ARM Lasse Langwadt Christensen <langwadt@fonz.dk> - 2016-02-23 14:29 -0800
        Re: Union of bitfields and larger type on ARM David Brown <david.brown@hesbynett.no> - 2016-02-24 08:51 +0100
          Re: Union of bitfields and larger type on ARM Les Cargill <lcargill99@comcast.com> - 2016-02-25 12:08 -0600
            Re: Union of bitfields and larger type on ARM bitrex <bitrex@de.lete.earthlink.net> - 2016-02-25 13:43 -0500
      Re: Union of bitfields and larger type on ARM Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2016-02-23 22:02 +0200
    Re: Union of bitfields and larger type on ARM John Devereux <john@devereux.me.uk> - 2016-02-23 19:36 +0000
      Re: Union of bitfields and larger type on ARM David Brown <david.brown@hesbynett.no> - 2016-02-23 22:34 +0100
        Re: Union of bitfields and larger type on ARM bitrex <bitrex@de.lete.earthlink.net> - 2016-02-23 16:45 -0500
          Re: Union of bitfields and larger type on ARM David Brown <david.brown@hesbynett.no> - 2016-02-23 23:21 +0100
        Re: Union of bitfields and larger type on ARM spope33@speedymail.org (Steve Pope) - 2016-02-25 00:06 +0000
          Re: Union of bitfields and larger type on ARM David Brown <david.brown@hesbynett.no> - 2016-02-25 01:29 +0100
    Re: Union of bitfields and larger type on ARM Tim Wescott <seemywebsite@myfooter.really> - 2016-02-23 15:53 -0600
      Re: Union of bitfields and larger type on ARM David Brown <david.brown@hesbynett.no> - 2016-02-23 23:48 +0100
        Re: Union of bitfields and larger type on ARM Christian Gollwitzer <auriocus@gmx.de> - 2016-02-24 09:44 +0100
          Re: Union of bitfields and larger type on ARM David Brown <david.brown@hesbynett.no> - 2016-02-24 10:39 +0100
      Re: Union of bitfields and larger type on ARM Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2016-02-24 09:54 +0200
    Re: Union of bitfields and larger type on ARM M Philbrook <jamie_ka1lpa@charter.net> - 2016-02-23 20:39 -0500
      Re: Union of bitfields and larger type on ARM Ian Collins <ian-news@hotmail.com> - 2016-02-24 14:48 +1300
    Re: Union of bitfields and larger type on ARM David Brown <david.brown@hesbynett.no> - 2016-02-24 10:41 +0100
    Re: Union of bitfields and larger type on ARM Les Cargill <lcargill99@comcast.com> - 2016-02-25 12:05 -0600
      Re: Union of bitfields and larger type on ARM David Brown <david.brown@hesbynett.no> - 2016-02-26 17:09 +0100
        Re: Union of bitfields and larger type on ARM scott@slp53.sl.home (Scott Lurndal) - 2016-02-26 17:29 +0000
          Re: Union of bitfields and larger type on ARM David Brown <david.brown@hesbynett.no> - 2016-02-26 18:42 +0100
        Re: Union of bitfields and larger type on ARM Les Cargill <lcargill99@comcast.com> - 2016-02-26 19:07 -0600
        Re: Union of bitfields and larger type on ARM Allan Herriman <allanherriman@hotmail.com> - 2016-02-27 08:58 +0000
          Re: Union of bitfields and larger type on ARM David Brown <david.brown@hesbynett.no> - 2016-02-27 14:37 +0100

Page 1 of 2  [1] 2  Next page →


#400092 — Union of bitfields and larger type on ARM

Frombitrex <bitrex@de.lete.earthlink.net>
Date2016-02-23 14:17 -0500
SubjectUnion of bitfields and larger type on ARM
Message-ID<If2zy.23937$Nf2.15642@fx14.iad>
Does anyone know if the following "naughty" (implementation dependent) 
construct would work "correctly" on the ARM Cortex M4, compiled with 
arm-gcc-embedded?

typedef union {
       uint32_t phase_accumulator_full;
       struct {
         uint8_t integer_high : 8,
                 integer_low : 8,
                 frac_high  : 8,
                 frac_low  : 8;

       };
} phase_accumulator;

[toc] | [next] | [standalone]


#400099

FromLasse Langwadt Christensen <langwadt@fonz.dk>
Date2016-02-23 11:36 -0800
Message-ID<d5a8917b-f701-4878-ae0e-0d3c8f307d50@googlegroups.com>
In reply to#400092
Den tirsdag den 23. februar 2016 kl. 20.18.11 UTC+1 skrev bitrex:
> Does anyone know if the following "naughty" (implementation dependent) 
> construct would work "correctly" on the ARM Cortex M4, compiled with 
> arm-gcc-embedded?
> 
> typedef union {
>        uint32_t phase_accumulator_full;
>        struct {
>          uint8_t integer_high : 8,
>                  integer_low : 8,
>                  frac_high  : 8,
>                  frac_low  : 8;
> 
>        };
> } phase_accumulator;

that would depend on what you mean by correctly and what endianness you have

-Lasse

[toc] | [prev] | [next] | [standalone]


#400103

FromJohn Devereux <john@devereux.me.uk>
Date2016-02-23 19:40 +0000
Message-ID<87bn776wru.fsf@devereux.me.uk>
In reply to#400099
Lasse Langwadt Christensen <langwadt@fonz.dk> writes:

> Den tirsdag den 23. februar 2016 kl. 20.18.11 UTC+1 skrev bitrex:
>> Does anyone know if the following "naughty" (implementation dependent) 
>> construct would work "correctly" on the ARM Cortex M4, compiled with 
>> arm-gcc-embedded?
>> 
>> typedef union {
>>        uint32_t phase_accumulator_full;
>>        struct {
>>          uint8_t integer_high : 8,
>>                  integer_low : 8,
>>                  frac_high  : 8,
>>                  frac_low  : 8;
>> 
>>        };
>> } phase_accumulator;
>
> that would depend on what you mean by correctly and what endianness you have

Oh yes CM4 is generally little endian, and that does not seem to match
the struct!

-- 

John Devereux

[toc] | [prev] | [next] | [standalone]


#400104

Frombitrex <bitrex@de.lete.earthlink.net>
Date2016-02-23 14:42 -0500
Message-ID<2D2zy.35147$Fg2.20483@fx09.iad>
In reply to#400103
On 02/23/2016 02:40 PM, John Devereux wrote:
> Lasse Langwadt Christensen <langwadt@fonz.dk> writes:
>
>> Den tirsdag den 23. februar 2016 kl. 20.18.11 UTC+1 skrev bitrex:
>>> Does anyone know if the following "naughty" (implementation dependent)
>>> construct would work "correctly" on the ARM Cortex M4, compiled with
>>> arm-gcc-embedded?
>>>
>>> typedef union {
>>>         uint32_t phase_accumulator_full;
>>>         struct {
>>>           uint8_t integer_high : 8,
>>>                   integer_low : 8,
>>>                   frac_high  : 8,
>>>                   frac_low  : 8;
>>>
>>>         };
>>> } phase_accumulator;
>>
>> that would depend on what you mean by correctly and what endianness you have
>
> Oh yes CM4 is generally little endian, and that does not seem to match
> the struct!
>

I'm new to coding for the processor, and I had been having a little 
trouble determining what the endianness of the thing actually _is_...

[toc] | [prev] | [next] | [standalone]


#400105

Frombitrex <bitrex@de.lete.earthlink.net>
Date2016-02-23 14:46 -0500
Message-ID<bG2zy.1151$1i2.30@fx30.iad>
In reply to#400099
On 02/23/2016 02:36 PM, Lasse Langwadt Christensen wrote:
> Den tirsdag den 23. februar 2016 kl. 20.18.11 UTC+1 skrev bitrex:
>> Does anyone know if the following "naughty" (implementation dependent)
>> construct would work "correctly" on the ARM Cortex M4, compiled with
>> arm-gcc-embedded?
>>
>> typedef union {
>>         uint32_t phase_accumulator_full;
>>         struct {
>>           uint8_t integer_high : 8,
>>                   integer_low : 8,
>>                   frac_high  : 8,
>>                   frac_low  : 8;
>>
>>         };
>> } phase_accumulator;
>
> that would depend on what you mean by correctly and what endianness you have
>
> -Lasse
>

Well, I'd like to be able to increment the uint32_t, and then access the 
individual bytes through the union such that say if we have 0xAABBCCDD 
in the uint32_t, I'll have 0xAA in integer_high, 0xBB in integer_low, etc.

[toc] | [prev] | [next] | [standalone]


#400112

FromLasse Langwadt Christensen <langwadt@fonz.dk>
Date2016-02-23 12:23 -0800
Message-ID<9df5f74a-e2cc-469c-8221-91aed8c7fafa@googlegroups.com>
In reply to#400105
Den tirsdag den 23. februar 2016 kl. 20.46.22 UTC+1 skrev bitrex:
> On 02/23/2016 02:36 PM, Lasse Langwadt Christensen wrote:
> > Den tirsdag den 23. februar 2016 kl. 20.18.11 UTC+1 skrev bitrex:
> >> Does anyone know if the following "naughty" (implementation dependent)
> >> construct would work "correctly" on the ARM Cortex M4, compiled with
> >> arm-gcc-embedded?
> >>
> >> typedef union {
> >>         uint32_t phase_accumulator_full;
> >>         struct {
> >>           uint8_t integer_high : 8,
> >>                   integer_low : 8,
> >>                   frac_high  : 8,
> >>                   frac_low  : 8;
> >>
> >>         };
> >> } phase_accumulator;
> >
> > that would depend on what you mean by correctly and what endianness you have
> >
> > -Lasse
> >
> 
> Well, I'd like to be able to increment the uint32_t, and then access the 
> individual bytes through the union such that say if we have 0xAABBCCDD 
> in the uint32_t, I'll have 0xAA in integer_high, 0xBB in integer_low, etc.

the bytes are in the wrong order for a little-endian cpu, don't know of any M4 that isn't little-endian

And it don't think it'll compile unless you name the struct

-Lasse

[toc] | [prev] | [next] | [standalone]


#400122

Frombitrex <bitrex@de.lete.earthlink.net>
Date2016-02-23 16:50 -0500
Message-ID<mu4zy.2706$pL2.886@fx40.iad>
In reply to#400112
On 02/23/2016 03:23 PM, Lasse Langwadt Christensen wrote:
> Den tirsdag den 23. februar 2016 kl. 20.46.22 UTC+1 skrev bitrex:
>> On 02/23/2016 02:36 PM, Lasse Langwadt Christensen wrote:
>>> Den tirsdag den 23. februar 2016 kl. 20.18.11 UTC+1 skrev bitrex:
>>>> Does anyone know if the following "naughty" (implementation dependent)
>>>> construct would work "correctly" on the ARM Cortex M4, compiled with
>>>> arm-gcc-embedded?
>>>>
>>>> typedef union {
>>>>          uint32_t phase_accumulator_full;
>>>>          struct {
>>>>            uint8_t integer_high : 8,
>>>>                    integer_low : 8,
>>>>                    frac_high  : 8,
>>>>                    frac_low  : 8;
>>>>
>>>>          };
>>>> } phase_accumulator;
>>>
>>> that would depend on what you mean by correctly and what endianness you have
>>>
>>> -Lasse
>>>
>>
>> Well, I'd like to be able to increment the uint32_t, and then access the
>> individual bytes through the union such that say if we have 0xAABBCCDD
>> in the uint32_t, I'll have 0xAA in integer_high, 0xBB in integer_low, etc.
>
> the bytes are in the wrong order for a little-endian cpu, don't know of any M4 that isn't little-endian
>
> And it don't think it'll compile unless you name the struct
>
> -Lasse
>

I believe ISO C11 permits anonymous structs in general, and gcc supports 
them now in C++, C99, everything...

[toc] | [prev] | [next] | [standalone]


#400125

FromLasse Langwadt Christensen <langwadt@fonz.dk>
Date2016-02-23 14:11 -0800
Message-ID<6271e4d1-80de-4941-b350-db8b6b1423db@googlegroups.com>
In reply to#400122
Den tirsdag den 23. februar 2016 kl. 22.50.16 UTC+1 skrev bitrex:
> On 02/23/2016 03:23 PM, Lasse Langwadt Christensen wrote:
> > Den tirsdag den 23. februar 2016 kl. 20.46.22 UTC+1 skrev bitrex:
> >> On 02/23/2016 02:36 PM, Lasse Langwadt Christensen wrote:
> >>> Den tirsdag den 23. februar 2016 kl. 20.18.11 UTC+1 skrev bitrex:
> >>>> Does anyone know if the following "naughty" (implementation dependent)
> >>>> construct would work "correctly" on the ARM Cortex M4, compiled with
> >>>> arm-gcc-embedded?
> >>>>
> >>>> typedef union {
> >>>>          uint32_t phase_accumulator_full;
> >>>>          struct {
> >>>>            uint8_t integer_high : 8,
> >>>>                    integer_low : 8,
> >>>>                    frac_high  : 8,
> >>>>                    frac_low  : 8;
> >>>>
> >>>>          };
> >>>> } phase_accumulator;
> >>>
> >>> that would depend on what you mean by correctly and what endianness you have
> >>>
> >>> -Lasse
> >>>
> >>
> >> Well, I'd like to be able to increment the uint32_t, and then access the
> >> individual bytes through the union such that say if we have 0xAABBCCDD
> >> in the uint32_t, I'll have 0xAA in integer_high, 0xBB in integer_low, etc.
> >
> > the bytes are in the wrong order for a little-endian cpu, don't know of any M4 that isn't little-endian
> >
> > And it don't think it'll compile unless you name the struct
> >
> > -Lasse
> >
> 
> I believe ISO C11 permits anonymous structs in general, and gcc supports 
> them now in C++, C99, everything...

you are right, the anonymous struct does compile with the version of 
arm-none-eabi-gcc I have here

-Lasse

[toc] | [prev] | [next] | [standalone]


#400126

Frombitrex <bitrex@de.lete.earthlink.net>
Date2016-02-23 17:16 -0500
Message-ID<ES4zy.278$Uy1.259@fx29.iad>
In reply to#400125
On 02/23/2016 05:11 PM, Lasse Langwadt Christensen wrote:
> Den tirsdag den 23. februar 2016 kl. 22.50.16 UTC+1 skrev bitrex:
>> On 02/23/2016 03:23 PM, Lasse Langwadt Christensen wrote:
>>> Den tirsdag den 23. februar 2016 kl. 20.46.22 UTC+1 skrev bitrex:
>>>> On 02/23/2016 02:36 PM, Lasse Langwadt Christensen wrote:
>>>>> Den tirsdag den 23. februar 2016 kl. 20.18.11 UTC+1 skrev bitrex:
>>>>>> Does anyone know if the following "naughty" (implementation dependent)
>>>>>> construct would work "correctly" on the ARM Cortex M4, compiled with
>>>>>> arm-gcc-embedded?
>>>>>>
>>>>>> typedef union {
>>>>>>           uint32_t phase_accumulator_full;
>>>>>>           struct {
>>>>>>             uint8_t integer_high : 8,
>>>>>>                     integer_low : 8,
>>>>>>                     frac_high  : 8,
>>>>>>                     frac_low  : 8;
>>>>>>
>>>>>>           };
>>>>>> } phase_accumulator;
>>>>>
>>>>> that would depend on what you mean by correctly and what endianness you have
>>>>>
>>>>> -Lasse
>>>>>
>>>>
>>>> Well, I'd like to be able to increment the uint32_t, and then access the
>>>> individual bytes through the union such that say if we have 0xAABBCCDD
>>>> in the uint32_t, I'll have 0xAA in integer_high, 0xBB in integer_low, etc.
>>>
>>> the bytes are in the wrong order for a little-endian cpu, don't know of any M4 that isn't little-endian
>>>
>>> And it don't think it'll compile unless you name the struct
>>>
>>> -Lasse
>>>
>>
>> I believe ISO C11 permits anonymous structs in general, and gcc supports
>> them now in C++, C99, everything...
>
> you are right, the anonymous struct does compile with the version of
> arm-none-eabi-gcc I have here
>
> -Lasse
>

Does it complain if you do -pedantic?

[toc] | [prev] | [next] | [standalone]


#400128

FromLasse Langwadt Christensen <langwadt@fonz.dk>
Date2016-02-23 14:29 -0800
Message-ID<c807261a-e7d0-4229-985a-223d974a407e@googlegroups.com>
In reply to#400126
Den tirsdag den 23. februar 2016 kl. 23.16.08 UTC+1 skrev bitrex:
> On 02/23/2016 05:11 PM, Lasse Langwadt Christensen wrote:
> > Den tirsdag den 23. februar 2016 kl. 22.50.16 UTC+1 skrev bitrex:
> >> On 02/23/2016 03:23 PM, Lasse Langwadt Christensen wrote:
> >>> Den tirsdag den 23. februar 2016 kl. 20.46.22 UTC+1 skrev bitrex:
> >>>> On 02/23/2016 02:36 PM, Lasse Langwadt Christensen wrote:
> >>>>> Den tirsdag den 23. februar 2016 kl. 20.18.11 UTC+1 skrev bitrex:
> >>>>>> Does anyone know if the following "naughty" (implementation dependent)
> >>>>>> construct would work "correctly" on the ARM Cortex M4, compiled with
> >>>>>> arm-gcc-embedded?
> >>>>>>
> >>>>>> typedef union {
> >>>>>>           uint32_t phase_accumulator_full;
> >>>>>>           struct {
> >>>>>>             uint8_t integer_high : 8,
> >>>>>>                     integer_low : 8,
> >>>>>>                     frac_high  : 8,
> >>>>>>                     frac_low  : 8;
> >>>>>>
> >>>>>>           };
> >>>>>> } phase_accumulator;
> >>>>>
> >>>>> that would depend on what you mean by correctly and what endianness you have
> >>>>>
> >>>>> -Lasse
> >>>>>
> >>>>
> >>>> Well, I'd like to be able to increment the uint32_t, and then access the
> >>>> individual bytes through the union such that say if we have 0xAABBCCDD
> >>>> in the uint32_t, I'll have 0xAA in integer_high, 0xBB in integer_low, etc.
> >>>
> >>> the bytes are in the wrong order for a little-endian cpu, don't know of any M4 that isn't little-endian
> >>>
> >>> And it don't think it'll compile unless you name the struct
> >>>
> >>> -Lasse
> >>>
> >>
> >> I believe ISO C11 permits anonymous structs in general, and gcc supports
> >> them now in C++, C99, everything...
> >
> > you are right, the anonymous struct does compile with the version of
> > arm-none-eabi-gcc I have here
> >
> > -Lasse
> >
> 
> Does it complain if you do -pedantic?

I get a warning that ISO C99 doesn't support unnamed structs/unions

and about a trillion warning from cmsis code

-Lasse

[toc] | [prev] | [next] | [standalone]


#400183

FromDavid Brown <david.brown@hesbynett.no>
Date2016-02-24 08:51 +0100
Message-ID<najn90$u5i$1@dont-email.me>
In reply to#400105
On 23/02/16 20:46, bitrex wrote:
> On 02/23/2016 02:36 PM, Lasse Langwadt Christensen wrote:
>> Den tirsdag den 23. februar 2016 kl. 20.18.11 UTC+1 skrev bitrex:
>>> Does anyone know if the following "naughty" (implementation dependent)
>>> construct would work "correctly" on the ARM Cortex M4, compiled with
>>> arm-gcc-embedded?
>>>
>>> typedef union {
>>>         uint32_t phase_accumulator_full;
>>>         struct {
>>>           uint8_t integer_high : 8,
>>>                   integer_low : 8,
>>>                   frac_high  : 8,
>>>                   frac_low  : 8;
>>>
>>>         };
>>> } phase_accumulator;
>>
>> that would depend on what you mean by correctly and what endianness
>> you have
>>
>> -Lasse
>>
> 
> Well, I'd like to be able to increment the uint32_t, and then access the
> individual bytes through the union such that say if we have 0xAABBCCDD
> in the uint32_t, I'll have 0xAA in integer_high, 0xBB in integer_low, etc.
> 

In that case you have the ordering wrong.  The Cortex M devices are all
strictly little-endian, and the EABI requires little-endian bitfield
order too (it is possible for the bitfields to be in a different endian
order than multi-byte data - the bitfield endianness is a choice for the
ABI and/or compiler).

[toc] | [prev] | [next] | [standalone]


#400350

FromLes Cargill <lcargill99@comcast.com>
Date2016-02-25 12:08 -0600
Message-ID<nanfa7$v8s$1@dont-email.me>
In reply to#400183
David Brown wrote:
> On 23/02/16 20:46, bitrex wrote:
>> On 02/23/2016 02:36 PM, Lasse Langwadt Christensen wrote:
>>> Den tirsdag den 23. februar 2016 kl. 20.18.11 UTC+1 skrev bitrex:
>>>> Does anyone know if the following "naughty" (implementation dependent)
>>>> construct would work "correctly" on the ARM Cortex M4, compiled with
>>>> arm-gcc-embedded?
>>>>
>>>> typedef union {
>>>>          uint32_t phase_accumulator_full;
>>>>          struct xx {
>>>>            uint8_t integer_high : 8,
>>>>                    integer_low : 8,
>>>>                    frac_high  : 8,
>>>>                    frac_low  : 8;
>>>>
>>>>          } bob;
>>>> } phase_accumulator;
>>>
>>> that would depend on what you mean by correctly and what endianness
>>> you have
>>>
>>> -Lasse
>>>
>>
>> Well, I'd like to be able to increment the uint32_t, and then access the
>> individual bytes through the union such that say if we have 0xAABBCCDD
>> in the uint32_t, I'll have 0xAA in integer_high, 0xBB in integer_low, etc.
>>
>
> In that case you have the ordering wrong.  The Cortex M devices are all
> strictly little-endian, and the EABI requires little-endian bitfield
> order too (it is possible for the bitfields to be in a different endian
> order than multi-byte data - the bitfield endianness is a choice for the
> ABI and/or compiler).
>
>


I don't mean "this is an inappropriate question" but I'd think he could 
have the answer in 15 minutes or less by trying it.

To wit:

phase_accumulator p;

p.phase_accumulator_full = 0x012345678;

printf("p.bob.integer_high = %x\n",p.bob.integer_high);

etc. etc.

If'n ya ain't got no printfs, then you hopefully know how to deal with 
that.

-- 
Les Cargill

[toc] | [prev] | [next] | [standalone]


#400356

Frombitrex <bitrex@de.lete.earthlink.net>
Date2016-02-25 13:43 -0500
Message-ID<xXHzy.3943$GU5.1116@fx05.iad>
In reply to#400350
On 02/25/2016 01:08 PM, Les Cargill wrote:
> David Brown wrote:
>> On 23/02/16 20:46, bitrex wrote:
>>> On 02/23/2016 02:36 PM, Lasse Langwadt Christensen wrote:
>>>> Den tirsdag den 23. februar 2016 kl. 20.18.11 UTC+1 skrev bitrex:
>>>>> Does anyone know if the following "naughty" (implementation dependent)
>>>>> construct would work "correctly" on the ARM Cortex M4, compiled with
>>>>> arm-gcc-embedded?
>>>>>
>>>>> typedef union {
>>>>>          uint32_t phase_accumulator_full;
>>>>>          struct xx {
>>>>>            uint8_t integer_high : 8,
>>>>>                    integer_low : 8,
>>>>>                    frac_high  : 8,
>>>>>                    frac_low  : 8;
>>>>>
>>>>>          } bob;
>>>>> } phase_accumulator;
>>>>
>>>> that would depend on what you mean by correctly and what endianness
>>>> you have
>>>>
>>>> -Lasse
>>>>
>>>
>>> Well, I'd like to be able to increment the uint32_t, and then access the
>>> individual bytes through the union such that say if we have 0xAABBCCDD
>>> in the uint32_t, I'll have 0xAA in integer_high, 0xBB in integer_low,
>>> etc.
>>>
>>
>> In that case you have the ordering wrong.  The Cortex M devices are all
>> strictly little-endian, and the EABI requires little-endian bitfield
>> order too (it is possible for the bitfields to be in a different endian
>> order than multi-byte data - the bitfield endianness is a choice for the
>> ABI and/or compiler).
>>
>>
>
>
> I don't mean "this is an inappropriate question" but I'd think he could
> have the answer in 15 minutes or less by trying it.
>
> To wit:
>
> phase_accumulator p;
>
> p.phase_accumulator_full = 0x012345678;
>
> printf("p.bob.integer_high = %x\n",p.bob.integer_high);
>
> etc. etc.
>
> If'n ya ain't got no printfs, then you hopefully know how to deal with
> that.
>

I thought I had no printfs, but I discovered the other day that I can 
serial println to the console via USB on the development board I'm using...

[toc] | [prev] | [next] | [standalone]


#400109

FromTauno Voipio <tauno.voipio@notused.fi.invalid>
Date2016-02-23 22:02 +0200
Message-ID<naidmf$mok$1@dont-email.me>
In reply to#400099
On 23.2.16 21:36, Lasse Langwadt Christensen wrote:
> Den tirsdag den 23. februar 2016 kl. 20.18.11 UTC+1 skrev bitrex:
>> Does anyone know if the following "naughty" (implementation dependent)
>> construct would work "correctly" on the ARM Cortex M4, compiled with
>> arm-gcc-embedded?
>>
>> typedef union {
>>         uint32_t phase_accumulator_full;
>>         struct {
>>           uint8_t integer_high : 8,
>>                   integer_low : 8,
>>                   frac_high  : 8,
>>                   frac_low  : 8;
>>
>>         };
>> } phase_accumulator;
>
> that would depend on what you mean by correctly and what endianness you have
>
> -Lasse
>

At least those Cortexes I have used, (Atmel, Philips, STM)
are definitively little-endian.

-- 

-TV

[toc] | [prev] | [next] | [standalone]


#400101

FromJohn Devereux <john@devereux.me.uk>
Date2016-02-23 19:36 +0000
Message-ID<87fuwj6wyi.fsf@devereux.me.uk>
In reply to#400092
bitrex <bitrex@de.lete.earthlink.net> writes:

> Does anyone know if the following "naughty" (implementation dependent)
> construct would work "correctly" on the ARM Cortex M4, compiled with
> arm-gcc-embedded?
>
> typedef union {
>       uint32_t phase_accumulator_full;
>       struct {
>         uint8_t integer_high : 8,
>                 integer_low : 8,
>                 frac_high  : 8,
>                 frac_low  : 8;
>
>       };
> } phase_accumulator;

I am not an expert (ask on comp.arch.embedded) but my understanding is
that this sort of thing is guaranteed by the EABI (bugs aside).



-- 

John Devereux

[toc] | [prev] | [next] | [standalone]


#400119

FromDavid Brown <david.brown@hesbynett.no>
Date2016-02-23 22:34 +0100
Message-ID<naij2s$lsf$1@dont-email.me>
In reply to#400101
On 23/02/16 20:36, John Devereux wrote:
> bitrex <bitrex@de.lete.earthlink.net> writes:
>
>> Does anyone know if the following "naughty" (implementation dependent)
>> construct would work "correctly" on the ARM Cortex M4, compiled with
>> arm-gcc-embedded?
>>
>> typedef union {
>>        uint32_t phase_accumulator_full;
>>        struct {
>>          uint8_t integer_high : 8,
>>                  integer_low : 8,
>>                  frac_high  : 8,
>>                  frac_low  : 8;
>>
>>        };
>> } phase_accumulator;
>
> I am not an expert (ask on comp.arch.embedded) but my understanding is
> that this sort of thing is guaranteed by the EABI (bugs aside).
>

I can't even figure out why it would be considered "naughty" at all. 
The only implementation-dependent aspects I can see are the alignment of 
the parts (on the ARM, 8-bit, 16-bit and 32-bit types all have "natural" 
alignments), and the ordering of the bitfields (which is low bits first 
- guaranteed by the ARM EABI, and thus consistent across compilers).

[toc] | [prev] | [next] | [standalone]


#400121

Frombitrex <bitrex@de.lete.earthlink.net>
Date2016-02-23 16:45 -0500
Message-ID<aq4zy.56$uT1.16@fx27.iad>
In reply to#400119
On 02/23/2016 04:34 PM, David Brown wrote:
> On 23/02/16 20:36, John Devereux wrote:
>> bitrex <bitrex@de.lete.earthlink.net> writes:
>>
>>> Does anyone know if the following "naughty" (implementation dependent)
>>> construct would work "correctly" on the ARM Cortex M4, compiled with
>>> arm-gcc-embedded?
>>>
>>> typedef union {
>>>        uint32_t phase_accumulator_full;
>>>        struct {
>>>          uint8_t integer_high : 8,
>>>                  integer_low : 8,
>>>                  frac_high  : 8,
>>>                  frac_low  : 8;
>>>
>>>        };
>>> } phase_accumulator;
>>
>> I am not an expert (ask on comp.arch.embedded) but my understanding is
>> that this sort of thing is guaranteed by the EABI (bugs aside).
>>
>
> I can't even figure out why it would be considered "naughty" at all. The
> only implementation-dependent aspects I can see are the alignment of the
> parts (on the ARM, 8-bit, 16-bit and 32-bit types all have "natural"
> alignments), and the ordering of the bitfields (which is low bits first
> - guaranteed by the ARM EABI, and thus consistent across compilers).
>
>

"Naughty" if one wants to port the code as-is to another architecture, I 
guess.

[toc] | [prev] | [next] | [standalone]


#400127

FromDavid Brown <david.brown@hesbynett.no>
Date2016-02-23 23:21 +0100
Message-ID<nailqs$sd$1@dont-email.me>
In reply to#400121
On 23/02/16 22:45, bitrex wrote:
> On 02/23/2016 04:34 PM, David Brown wrote:
>> On 23/02/16 20:36, John Devereux wrote:
>>> bitrex <bitrex@de.lete.earthlink.net> writes:
>>>
>>>> Does anyone know if the following "naughty" (implementation dependent)
>>>> construct would work "correctly" on the ARM Cortex M4, compiled with
>>>> arm-gcc-embedded?
>>>>
>>>> typedef union {
>>>>        uint32_t phase_accumulator_full;
>>>>        struct {
>>>>          uint8_t integer_high : 8,
>>>>                  integer_low : 8,
>>>>                  frac_high  : 8,
>>>>                  frac_low  : 8;
>>>>
>>>>        };
>>>> } phase_accumulator;
>>>
>>> I am not an expert (ask on comp.arch.embedded) but my understanding is
>>> that this sort of thing is guaranteed by the EABI (bugs aside).
>>>
>>
>> I can't even figure out why it would be considered "naughty" at all. The
>> only implementation-dependent aspects I can see are the alignment of the
>> parts (on the ARM, 8-bit, 16-bit and 32-bit types all have "natural"
>> alignments), and the ordering of the bitfields (which is low bits first
>> - guaranteed by the ARM EABI, and thus consistent across compilers).
>>
>>
>
> "Naughty" if one wants to port the code as-is to another architecture, I
> guess.

I would say "non-portable" rather than "naughty".  "Naughty" implies 
that this might not work in some circumstances, or perhaps depends on 
undefined behaviour.  This is merely non-portable and relies on 
implementation-dependent behaviour (which happens to be defined by the 
ARM EABI, and thus should apply to all ARM compilers).

[toc] | [prev] | [next] | [standalone]


#400265

Fromspope33@speedymail.org (Steve Pope)
Date2016-02-25 00:06 +0000
Message-ID<nalgif$8oi$1@blue-new.rahul.net>
In reply to#400119
David Brown  <david.brown@hesbynett.no> wrote:

>On 23/02/16 20:36, John Devereux wrote:

>> bitrex <bitrex@de.lete.earthlink.net> writes:

>> I am not an expert (ask on comp.arch.embedded) but my understanding is
>> that this sort of thing is guaranteed by the EABI (bugs aside).

>I can't even figure out why it would be considered "naughty" at all. 
>The only implementation-dependent aspects I can see are the alignment of 
>the parts (on the ARM, 8-bit, 16-bit and 32-bit types all have "natural" 
>alignments), and the ordering of the bitfields (which is low bits first 
>- guaranteed by the ARM EABI, and thus consistent across compilers).

Under K&R C the ordering of fields was not guaranteed, but I
think this was cleaned up by C99 or possibly somewhat later.

OP should see which language standard their compiler uses and
refer to that standard and comment appropriately. (In addition to 
testing the code...)

Steve

[toc] | [prev] | [next] | [standalone]


#400270

FromDavid Brown <david.brown@hesbynett.no>
Date2016-02-25 01:29 +0100
Message-ID<nalhnc$t1g$1@dont-email.me>
In reply to#400265
On 25/02/16 01:06, Steve Pope wrote:
> David Brown  <david.brown@hesbynett.no> wrote:
>
>> On 23/02/16 20:36, John Devereux wrote:
>
>>> bitrex <bitrex@de.lete.earthlink.net> writes:
>
>>> I am not an expert (ask on comp.arch.embedded) but my understanding is
>>> that this sort of thing is guaranteed by the EABI (bugs aside).
>
>> I can't even figure out why it would be considered "naughty" at all.
>> The only implementation-dependent aspects I can see are the alignment of
>> the parts (on the ARM, 8-bit, 16-bit and 32-bit types all have "natural"
>> alignments), and the ordering of the bitfields (which is low bits first
>> - guaranteed by the ARM EABI, and thus consistent across compilers).
>
> Under K&R C the ordering of fields was not guaranteed, but I
> think this was cleaned up by C99 or possibly somewhat later.

I haven't looked at K&R for an older definition, but C11 certainly says 
that the order of allocation of bit-fields is implementation-dependent. 
  There are some rules about packing, but there is plenty of scope for 
weird implementations if the compiler writers so fancy.

>
> OP should see which language standard their compiler uses and
> refer to that standard and comment appropriately. (In addition to
> testing the code...)
>

As long as his compiler follows the ARM EABI (and all serious embedded 
ARM compilers will do so), there should be no problem - the EABI gives 
more details for this sort of thing than any of the C or C++ standards.

(He could make it a little easier by dropping the bitfields - they are 
not necessary when the struct fields are uint8_t and the bitfields are 8 
bits.)

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | sci.electronics.design


csiph-web