Thursday, January 27, 2011

some some

The extern in a function's declaration is sometimes used to indicate that the function's
definition is in some other source file, but there is no difference between
extern int function_name();
and
int function_name();

Inline functions are similar to macros because they both are expanded at compile time, but the macros are expanded by the preprocessor, while inline functions are parsed by the compiler. There are several important differences:
Inline functions follow all the protocols of type safety enforced on normal functions.
Inline functions are specified using the same syntax as any other function except that they include the inline keyword in the function declaration.
Expressions passed as arguments to inline functions are evaluated once. In some cases, expressions passed as arguments to macros can be evaluated more than once.

run this code:

#include
/*
int foo(int a);
int foo2(int a, int b);
*/
int main(int a)
{
int (*fp)(int a);
a = foo();
a = foo2(1);
exit(0);
}
int foo(int a)
{
return(a);
}
int foo2(int a, int b)
{
return(a+b);
}

run this again by removing /* and */. Understand the difference.

Whats short-circuiting in C expressions?
What this means is that the right hand side of the expression is not evaluated if the left
hand side determines the outcome. That is if the left hand side is true for || or false for
&&, the right hand side is not evaluated.

i = i++ /// invalid

• auto - local variables.
• static - variables are defined in a nonvolatile region of memory such that they
retain their contents though out the program's execution.
• register - asks the compiler to devote a processor register to this variable in order
to speed the program's execution. The compiler may not comply and the variable
looses it contents and identity when the function it which it is defined terminates.
• extern - tells the compiler that the variable is defined in another module.

How can I convert numbers to strings (the opposite of atoi)?
Use sprintf()
Note!, since sprintf() is also a variable argument function, it fails badly if passed with
wrong arguments or if some of the arguments are missed causing segmentation faults.


http://www.cprogramming.com/tutorial/computersciencetheory/sortcomp.html

No comments:

Post a Comment