Re: HELP ON C
Let's see what we can say about these
sacrpio said:
1. How can u implement a class in C.
You can't ;-)
class is a keyword that isn't supported in C (it's a C++ keyword)
You can use a struct and do some object oriented programming in C. But it will be limited and some construction will be not very intuitive.
sacrpio said:
Dear All,
2. What is difference between MACRO & INLINE Function.
A MACRO is a preprocessor statement. The C preprocessor just replaces the code where you use the macro with the code defined in the macro. It is done before compilation! MACRO's can cause strange errors since the compiler doesn't know the definition of the macro. It only sees the code generated by the preprocessor.
An inline function is a piece of code that is replaced by the compiler. If you make a call to an inline function, no function call is compiled.
for example:
if you create a function to update a variable, the compiler translates this into a function call, update the variable, and a return from the function.
if you create an inline function this is just the update of the variable.
=> inline is faster but expands your code size allot if it is used incorrect!
Both a Macro and an inline function have the same purpose. Avoid the function call. But they are done on a different level (preprocessor<->compiler). Best is to use inline functions when possible. It will be easier to debug.
sacrpio said:
3. What is the application of UNION.
A union is used when you want to address the same memory in different ways without having to use those ugly casts!
eg. you want to use a 16-bit value as a 16-bit integer or as 2 8-bit chars (high and low).
sacrpio said:
4. Why we use pointer to functions.
Don't use them if you don't know why they are used ;-).
Pointers to functions can be used to create more general functions.
eg. if you create a general sort function for objects (not specified) and define the biggerThen function for each object you want to sort.
Or you could use it to define a callback function. (eg, if you want to specify the function to be called when a timer is finished)
sacrpio said:
5. What is difference between STATIC & GLOBAL STATIC.
Static variables (source:
http://crasseux.com/books/ctutorial/Static-variables.html)
A second important storage class specifier is static. Normally, when you call a function, all its local variables are reinitialized each time the function is called. This means that their values change between function calls. Static variables, however, maintain their value between function calls.
Every global variable is defined as static automatically. (Roughly speaking, functions anywhere in a program can refer to a global variable; in contrast, a function can only refer to a local variable that is "nearby", where "nearby" is defined in a specific manner. See Scope, for more information on global variables. See Expressions and operators, for an example of a static local variable.)
Hope this helps
Antharax