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


Groups > sci.electronics.design > #400128

Re: Union of bitfields and larger type on ARM

Newsgroups sci.electronics.design
Date 2016-02-23 14:29 -0800
References (2 earlier) <bG2zy.1151$1i2.30@fx30.iad> <9df5f74a-e2cc-469c-8221-91aed8c7fafa@googlegroups.com> <mu4zy.2706$pL2.886@fx40.iad> <6271e4d1-80de-4941-b350-db8b6b1423db@googlegroups.com> <ES4zy.278$Uy1.259@fx29.iad>
Message-ID <c807261a-e7d0-4229-985a-223d974a407e@googlegroups.com> (permalink)
Subject Re: Union of bitfields and larger type on ARM
From Lasse Langwadt Christensen <langwadt@fonz.dk>

Show all headers | View raw


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

Back to sci.electronics.design | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web