|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Pointers to structs?
I'm trying to abstract relays into a structure with a forward and reverse element. The idea is to have a single set_relay() funtion that takes a pointer to this data structure as it's input.
I can't figure out how to get mcc to accept my syntax. I've been referencing a lot of documents, so I'm pretty sure my syntax is correct, but I haven't verified it with gcc or what not. I'm going to go do that now and then post some of my example code. Was just wondering if there's problems to start with though. |
|
#2
|
||||||
|
||||||
|
Re: Pointers to structs?
We had this discussion (well, not really a discussion, but a comment) in another thread. http://www.chiefdelphi.com/forums/sh...9&postcount=19
depending on how you are doing it, you may need to make your own macros. |
|
#3
|
||||
|
||||
|
Re: Pointers to structs?
After some testing in gcc, I figured it out. The more descriptive errors helped. The page I was reading was incorrect about the ordering of the type name versus the variable name. I'm actually passing a bitmask value that I #defined as a bitmask, but I just did it this way so it's easier for people to understand the pointer stuff that's going on. It's so nice having full ansi C.
Code:
struct relay_type { int fwd; int rev};
struct relay_type ball_arm_lower;
void set_relay (struct relay_type *relay, int fwd, int rev)
{
relay->fwd = fwd;
relay->rev = rev;
}
main()
{
update_inputs ();
set_relay (&ball_arm_lower, 1, 0);
update_outputs ();
}
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Laser Pointers.. | archiver | 2001 | 18 | 24-06-2002 00:08 |