Bitfields error

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did some experimenting with bit fields earlier today and after trying to run a quick debugging session to see the values inside the structure, the debugging session kept crashing out on me.

 

Here is the complete code that I was working with.

 

#include <avr/io.h>

typedef struct {
   int Zero : 1;
   int One : 1;
   int Two : 1;
   int Three : 1;
   int Four : 1;
   int Five : 1;
   int Six : 1;
   int Seven : 1;
} BitFields_t;

BitFields_t Bits;

int main(void)
{
    /* Replace with your application code */
    while (1)
    {
    }
}

You can see the error that AS7 threw at me in the attached image. This happens when trying to branch open the Bits variable. Anyone know what's going wrong here? I tried the same thing with a GCC C++ project and it works fine, but GCC C projects do this every time. I'll admit bit fields are something I only just discovered today (everyday's a school day ha!) so I'm not entirely sure what I'm trying to do is actually possible in C/ GCC C, and the fact that it doesn't work in a GCC C project but does in a GCC C++ project would suggest it can't, however everything I've read seems to suggest it can be done in C. Any ideas?

Attachment(s): 

This topic has a solution.
Last Edited: Sat. Sep 17, 2016 - 09:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try switching the debugger to avr-gdb - it's probably unlikely to crash the back end

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is Bits being swallowed by optimization since it isn't referenced anywhere?

Letting the smoke out since 1978

 

 

 

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

digitalDan wrote:

Is Bits being swallowed by optimization since it isn't referenced anywhere?

 

I don't think so since the debugger knows the memory location.

 

clawson wrote:

Try switching the debugger to avr-gdb

 

Gave it a shot but no effect, thanks for the suggestion though!

Anyway, I tried changing the ints in the structure to unsigned chars and it seemed to cure it? Not sure why but it's working!