Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Pointers to structs? (http://www.chiefdelphi.com/forums/showthread.php?t=25438)

Jeff McCune 16-02-2004 18:28

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.

Joe Ross 16-02-2004 18:39

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.

Jeff McCune 17-02-2004 13:17

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 ();
}



All times are GMT -5. The time now is 23:43.

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