Go to Post I don't mind being odd...I like to - listen - to Dean Kamen's speeches. They make sense. I don't get to listen to a lot of sense in the world, just a lot of noise. - JaneYoung [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 21-06-2009, 19:59
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
PPC bool bitfield

I was working on a library to make some tasks easier on the cRIO, and the library contained a bitfield that looks like this:
Code:
union ORArgs
{
	unsigned char Value;
	struct b
	{
		bool b0 : 1,
		b1 : 1, 
		b2 : 1, 
		b3 : 1, 
		b4 : 1, 
		b5 : 1, 
		b6 : 1, 
		b7 : 1;
	} Bits;
};
later, I read that bools are 4 bytes on a PPC system, which we have in the crio, and was wondering if the four bytes would cause undesired effects, like set b0,b1,b2, and b3 to true if b1 is set to true, but after thinking about it for a while, I thought that the first bit of bool b0 would equal the first bit of char Value, and the rest of the bits would be "discarded". unfortunately, I won't have access to the cRIO for another week. Is my first thought or second thought the true one?
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote
  #2   Spotlight this post!  
Unread 21-06-2009, 21:13
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: PPC bool bitfield

I don't think either is correct.

The ": 1" part of the definition specifies how many bits wide to make the element. If the compiler does what it is hinted to do, the eight booleans will take up exactly one byte. That will map precisely onto the one-byte char also defined in the union.
Reply With Quote
  #3   Spotlight this post!  
Unread 21-06-2009, 23:59
daltore's Avatar
daltore daltore is offline
Electronics/programming/design
AKA: Aaron Osmer
FRC #3529 (ausTIN CANs)
Team Role: Mentor
 
Join Date: Dec 2007
Rookie Year: 2007
Location: San Antonio, TX
Posts: 272
daltore has a spectacular aura aboutdaltore has a spectacular aura aboutdaltore has a spectacular aura about
Send a message via AIM to daltore Send a message via MSN to daltore Send a message via Yahoo to daltore
Re: PPC bool bitfield

Since you're specifying the type "bool", I believe the first four make up one bool variable, and the next 4 make up a second bool variable. If you made it a 10-bit bitfield, you'd end up with bool variables and 2 unused bits. At least, that's my understanding. From what I've read on bitfields, that code should be fine. The variable type declarations are really more just the computer's version of bureaucracy, it tells it how to write the memory addresses.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PPC 970FX Beats P4 and AMD64 Joe Matt Chit-Chat 4 14-02-2004 14:52
bool Variables, Autonomous Mode lasindi Programming 6 22-01-2004 22:26


All times are GMT -5. The time now is 13:36.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi