Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   How to manipulate a variable value using an array? (http://www.chiefdelphi.com/forums/showthread.php?t=60075)

lukevanoort 13-12-2007 21:25

Re: How to manipulate a variable value using an array?
 
The problem is what MPLAB says it is, you cannot reference (aka have a pointer to) a bitfield, relay outputs and, I assume, joystick switch states are stored in bitfields.

amateurrobotguy 13-12-2007 21:28

Re: How to manipulate a variable value using an array?
 
I know they are defined in ifi_aliases.h with the #define. So how do I get them out of bitfields? Do i need to "redeclare" them as ints?

lukevanoort 13-12-2007 21:44

Re: How to manipulate a variable value using an array?
 
When I was trying to write a generalized, modular library for FRC robots (something like WPIlib, but not as high level), I ran into this same issue, but with relay outputs. My solution was to use a structure for storing the values then, at the end of the program loop, call a function that assigned the values in the structure to the actual relays. I think you could do something similar in your case; for example, you could just assign the values of the switches to the various variables in your array at the beginning of every program cycle.

kevin.li.rit 13-12-2007 22:54

Re: How to manipulate a variable value using an array?
 
Quote:

Originally Posted by amateurrobotguy (Post 658722)
I know they are defined in ifi_aliases.h with the #define. So how do I get them out of bitfields? Do i need to "redeclare" them as ints?

I don't think you can redefine them to an INT since it's using a structure.

Phil Mack 13-12-2007 23:29

Re: How to manipulate a variable value using an array?
 
Quote:

Originally Posted by amateurrobotguy (Post 658704)
cannot reference the address of a bitfield

Each of these names refers to a single bit, not a byte. Because each symbol is referring to a bit and not a byte, an address is insufficient to identify the symbol. The wikipedia article http://en.wikipedia.org/wiki/Bitfield explains the concept very well.

Quote:

Originally Posted by amateurrobotguy
So how do I get them out of bitfields?

You must look to where the bit field is defined, and manipulate the struct. However, that seems somewhat counter to what you are attempting.

~Phil

amateurrobotguy 14-12-2007 00:17

Re: How to manipulate a variable value using an array?
 
So much for elegant coding...

But i think lukevanoort's workaround will work, just as long as I put it all in a separate function. My goal with this was just to clean up a billion if-thens into a for loop but i guess a if-then function will make the code easier to read anyways.


All times are GMT -5. The time now is 19:41.

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