How should I group these variables?
Posted
by
stariz77
on Programmers
See other posts from Programmers
or by stariz77
Published on 2012-04-08T13:57:05Z
Indexed on
2012/04/08
17:45 UTC
Read the original article
Hit count: 211
I have a shape that will be defined by:
char s_type;
char color;
double height;
double width;
These variables are scanned in from a request string sent to my server and passed into my printing function, which then prints out the shape. Currently they are just local variables sitting in my main()
; however, I was wondering if there would be any advantage in creating a struct containing these variables, and then passing the struct to my printing function? or how else might I improve my program's structure/style, would passing a struct by reference have any kind of performance benefit if there were many requests and therefore many printing function calls?
printer(char st, char cr, double ht, double wd);
int main()
{
// Other main functionality.
char s_type;
char color;
double height;
double width;
sscanf (serv_req, "GET /%c/%c/%lf/%lf", &s_type, &color, &height, &width);
printer(s_type, color, height, width);
// Other main functionality.
return 0;
}
It seemed "neater" if I had a struct or something that didn't leave me with declarations in the middle of everything else going on in main. I'm interested in structure/style as well as performance.
EDIT: didn't mean to put printer declaration inside main.
© Programmers or respective owner