Dear All,
I've inherited a real-time test rig control system without any documentation and despite reading a couple of books and the articles on this site, I'm still getting confused by pointers to structures.
I have highlighted three problems, which I've tried to reduce to the simplest case. Any help that can be offered would be most appreciated.
The struct is defined and named outside the main function in the line,
Problem 1: This is followed immediately by the below function. (cmd has not previously been declared.) Can you declare a previously unknown pointer when declaring the arguments of a function? Also, does this argument constitute a definition of a pointer to a struct of type GuiMessage?Code:typedef struct {int command; int intValue; double floatValue;} GuiMessage;
Problem 2: Now within the main function, the lineCode:void send_command(GuiMessage *cmd) { rtf_put(cmd, sizeof(GuiMessage)); }
seems to declare a struct, not a pointer to a struct, called cmd AND a pointer to a struct of type GuiMessage called buf. Are you allowed to give the same name to both a struct and a pointer to a struct because of 'name space'?Code:GuiMessage cmd, *buf;
Problem 3: The following line lies within a function called by main.
What does the following sytax do? Am I right in thinking that this means that all of the values in the struct pointer to by cmd are set to 0?
Any help would be greatly appreciated.Code:GuiMessage cmd={0};
Thanks,
TJHC