Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I was going through global and static variables.I have a question.
If I have a .c file and it is having only one user defined function(ABC()). Suppose I have to preserve the value of a variable in that function. Should I make that variable static(locally in that function) or make it global. Which one is best way and why.
Rule of thumb: Define variables/functions in the smallest scope possible while avoiding redundant code and data.
I recommend making the variable a static variable defined in the scope of the function.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 21 days ago.
Improve this question
is there a way to obtain function's parameters, inside this function, without passing it. Like the func providing the function name. i'd like to obtain just name of parameters, not type.
search with google, found functions for line, function name and file name but nothing about parameters
The C standard does not provide any facility for this.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I just had a question that whenever I write code I had to call all functions (predefined or user defined) in order to use or execute them. So why we don't have to call main function?
The main function is defined by the language itself as the designated start of the program. You don't need to call it because, in effect, your operating system (Linux, macOS, Windows, etc.) does.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
This is a slightly subjective answer, but how large do you think a structure should be before you start using pointers to it in other structures or function calls rather than the structure by-value?
Depends on the compiler and architecture.
C and C++ define the size of the types they use, and how functions are written, but they don't define how they are implemented.
This is means the standard itself doesn't define how the structurs are passed, just that they are in essence copied.
The compiler might decide to do something else entirely, like not copying the struct at all if there's a default copy constructor , and the variable isn't used.
But after saying all that, most common-sense compiler implementations would store the struct in a register if it fits. So depends on the architecture, make sure the structure fits in a register.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'd love to create some part dynamically. Would it be possible to use offsetof with string as a second argument? Something like:
offsetof( tic, "close.v");
Or can I convert char to member anyhow?
The offsetof construct is a compile time operation. It can't be used with anything that is generated dynamically.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have 2 functions in my code, namely void compare(...) and void checklist(...).
In void compare(...), I have if statement that has been defined as Reselection.
Now, I need to use the goto function from void checklist(...) to go to Reselection in void compare(...).
Since I know that the goto function can only be used within that function, I was wondering if there are other function that works as goto function but can be used in different void functions?
No, labels are local to the function in which they are defined. And programs would be a real mess otherwise.
You should make Reselection a function of its own.