(I am not a C programmer to start off so bare with me) I am taking 3 independent programs, that once ran independently (one would dump a message into MQSeries, another would pick it up)
Now it is being merged into a multithreaded single application.
So file wise we have 3 files (I am just not nearly as savvy with C as I am with java, and I am trying to encapsulate my code more than it currently is)
each thread calls a function from a specific file with 3 functions defined in it.
i.e.
Main calls FuncA, Funcb, and FuncC from Functions file. (functions, has no main method, the only thing coded into it are the includes, and 3 methods that perform various actions.)
Nested functions are not an option(but would be perfect if they were).
Here is the problem (I little psuedo code snippet)
The problem is I have 3 functions in a file that are completely independant of eachother. Then I need to add functions that will manipulate a global variables. It would be a mess to define global variables for all 3 of the primary functions at the head of the file.
1. In this situation where the main file is just calling a function in the functions file, if I did define global variables after the includes in functions.c would it even work how I would intend?
2. If so yes, would the better option be to go against what was previously set up for me and eliminate the functions file and create 3 seperate files for the 3 primary functions that will be called from main to house their primary function and associated functions?
3. If I connect to a database in FuncA, will I be able to execute sql in any functions I call from funcA.
As it stands the functions.c just has the 3 functions, I coded all the logic in order in each of the methods (which makes it incredibly hard to read, and just flat out looks bad, I want to create functions out of the big operations in these functions, just so the code in the functions is more readable)
Now it is being merged into a multithreaded single application.
So file wise we have 3 files (I am just not nearly as savvy with C as I am with java, and I am trying to encapsulate my code more than it currently is)
each thread calls a function from a specific file with 3 functions defined in it.
i.e.
Main calls FuncA, Funcb, and FuncC from Functions file. (functions, has no main method, the only thing coded into it are the includes, and 3 methods that perform various actions.)
Nested functions are not an option(but would be perfect if they were).
Here is the problem (I little psuedo code snippet)
Code:
int funcA(){
int rc = 0;
char *hello="HELLO";
rc = funcB(hello);
/*
what is the value of hello in funcA....HELLO or GOODBYE? I need it to be GOODBYE (which in this scenario most likely is not the case.)
*/
return 0;
}
int funcB(char *hell_ptr){
hell_ptr = "GOODBYE";
return 0;
}
The problem is I have 3 functions in a file that are completely independant of eachother. Then I need to add functions that will manipulate a global variables. It would be a mess to define global variables for all 3 of the primary functions at the head of the file.
1. In this situation where the main file is just calling a function in the functions file, if I did define global variables after the includes in functions.c would it even work how I would intend?
2. If so yes, would the better option be to go against what was previously set up for me and eliminate the functions file and create 3 seperate files for the 3 primary functions that will be called from main to house their primary function and associated functions?
3. If I connect to a database in FuncA, will I be able to execute sql in any functions I call from funcA.
As it stands the functions.c just has the 3 functions, I coded all the logic in order in each of the methods (which makes it incredibly hard to read, and just flat out looks bad, I want to create functions out of the big operations in these functions, just so the code in the functions is more readable)
Last edited: