Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 C


  TIOBE : C overtakes Java as the No.1 programming language

TIOBE has released the Programming Community Index for April 2012. The highlight of this month is that C overtakes Java as the No.1 programming language again. C language is liked by more and more developers of all ages. Due to the growing popularity of the Android platform, Java decline will not be obvious. Previously Java took a very long time to overtake C, now C once again returns to the throne. The battle between these two languages will continue.The top three are respectively, C, Java and C + +. Objective-C continues to heat up, while C# drops to No.5.Other interesting moves this m...

155,135 4       JAVA C.TIOBE


  do {...} while (0) in macros

If you are a C programmer, you must be familiar with macros. They are powerful and can help you ease your work if used correctly. However, if you don't define macros carefully, they may bite you and drive you crazy. In many C programs, you may see a special macro definition which may seem not so straightforward. Here is one example:#define __set_task_state(tsk, state_value) \ do { (tsk)->state = (state_value); } while (0)There are many this kind of macros which uses do{...}while(0) in Linux kernels and other popular C libraries. What's the use of this macro? Robert Love from Google(...

139,927 14       C C++ MACRO


  The ugliest C feature:

<tgmath.h> is a header provided by the standard C library,introduced in C99 to allow easier porting of Fortran numerical software to C.Fortran, unlike C, provides “intrinsic functions”, which are a part of the language and behave more likeoperators. While ordinary (“external”) functions behave similarly to C functions with respect to types(the types of arguments and parameters must match and the restult type is fixed), intrinsic functions accept arguments of several types and their return type may depend on the type of their arguments.For example Fortran 77 provid...

45,775 0       C FORTRAN INTRINSIC FUNCTIONS C99 UGLY


  gethostbyname vs getaddrinfo

getaddrinfo is slower than ping when resolving domain names. I think ping uses gethostbyname to resolve a domain name. The question becomes whether getaddrinfo is slower than gethostbyname. After testing with both functions, we find that getaddrinfo is really slow compared to gethostbyname. By strace tracking,  we find getaddrinfo will communicate with DNS server 10 times and gethostbyname will communicate with DNS server communication twice.gethostbyname is an old way to resolve domain name, The disadvantage of it is that it does not support IPV6, so there is a gethostbyname2 which repla...

20,645 0       C++ NETWORK DNS


  Read white space with scanf()

Usually, when we want to enter string with white spaces in C, we need to call gets() or fgets(0 method. We usually will not use scanf(0 or fscanf() because they cannot accept white spaces when scan user inputs. But when we specify the format in scanf() function, we may read strings with white space. the code section below illustrate this:#include <stdio.h> int main(int argc,char **argv){       char name[30];    fprintf(stdout,"Please enter the name : \n");fscanf(stdin,"%[^\n]s",name); fprintf(stdout,"%s\n",name); return 0;} On a...

19,878 0       C SCANF WHITE SPACE STRING FORMAT


  Error handling style in C

Following are three error handling styles in C.Which one you like the most? Or you don't like any one?1. /* Problem : Not enough. Easy to be wrong */int foo(int bar){        int return_value = 0;        int doing_okay = 1;        doing_okay = do_something( bar );        if (doing_okay)        {                doing_oka...

19,773 13       C ERROR HANDLING STYLE GOTO NESTED IF


  C Macro Tips and Tricks

Preprocessor vs CompilerTo properly understand C macros, you must understand how a C program is compiled. In particular, you must understand the different things that happen in the preprocessor and in the compiler.The preprocessor runs first, as the name implies. It performs some simple textual manipulations, such as:Stripping comments. Resolving #include directives and replacing them with the contents of the included file. Evaluating #if and #ifdef directives. Evaluating #defines. Expading the macros found in the rest of the code according to those #defines.It is, of course, these...

18,387 0       C MACRO PREPROCESSOR TRICK


  HeartBleed: Should C be blamed for the HeartBleed bug?

There is a discussion about the security of applications written in C on Hacker News recently after the report of HeartBleed bug in OpenSSL. In this discussion, some people are saying that the applications written in C are unsafe. It seems all or most of the faults should be laid on C. I think this is biased. The language itself should not be blamed.Safety is a relative term for programming languages. No language is absolutely safe. We claim some languages like Java and C# are safer than C/C++ because they have memory protection mechanism built in, we cannot access arbitrary memory locations i...

14,098 5       C ANALYSIS CODE REVIEW HEARTBLEED