ALL


  Algorithm : Reverse singly linked list

Questions about singly linked list are the lovers of interviewers during interviews given the characteristic that singly linked list is one-directional list and it's difficult to get the previous node of one node without some buffering tricks. In this post, we will demonstrate one of the most frequently asked question about singly linked list -- Reversing the singly list.Given the first node of a singly linked list, reverse the singly linked list. For example :A->B->C->DAfter reverse, it becomes:D->C->B->AThe general idea here is to changing the next node of one to its p...

5,795 0       C ALGORITHM INTERVIEW


  Algorithm : Delete middle node from singly linked list

Questions about singly linked list are frequently asked during technical interviews. Today we will share with you one algorithm question about singly linked list. Here is the problem description.Assuming the only information you are giving is there is a pointer to a middle node of a singly linked list, no other information about the linked list is given. Please delete this node and don't affect the structure of the linked list.Initially you may think this question is easy if you know the head node of the linked list, but unfortunately we don't know what the head is and hence we cannot know the...

8,764 0       C ALGORITHM LINKED LIST


  A trick of building multithreaded application on Solaris

Firstly, Let’s see a simple multithreaded application:#include <stdio.h>#include <pthread.h>#include <errno.h>void *thread1_func(void *p_arg){ errno = 0; sleep(3); errno = 1; printf("%s exit, errno is %d\n", (char*)p_arg, errno);}void *thread2_func(void *p_arg){ errno = 0; sleep(5); printf("%s exit, errno is %d\n", (char*)p_arg, errno);}int main(void){ pthread_t t1, t2; pthread_create(&t1, NULL, thread1_func, "Thread 1"); pthread_create(&t2, NULL, thread2_func, "Thread 2")...

5,428 0       C SOLARIS


  Do we need other languages other than C and C++?

There were hundreds of or thousands of programming languages created since the invention of computer. All these languages have the same target which is to make the computer do what we want it do. So we may find that many languages have the same functions, i.e, one task can be completed by one language can be completed by another language as well. Now we may wonder why we need so many different languages. Can we just have C or C++ since they provide the best performance we need. The answer obviously is no.We do need other languages other than C and C++. Here are the reasons.The creation of diff...

9,051 0       C PROGRAMMING LANGUAGE ERLANG


  C programming tips in SPARC architecture

If you are a newbie of C programmers in SPARC architecture (For example, working on Solaris), you should pay attention to the following tips:(1) By default, SPARC is big-endian (For Endianness, you can refer http://en.wikipedia.org/wiki/Endianness). It means for an integer (short, int, long, etc), the MSB will be stored in the lower address, while the LSB will be stored in the higher address. (2) SPARC requires byte-alignment. It means for a short (2 bytes long) variable, the start address of the variable must be the multiples of 2, while a int (4 bytes long) variable, the start...

6,746 0       C


  Socket programming tips in Solaris

I sponsored a topic in stackoverflow.com, and hoped the programmers can share the socket programming tips in different UNIX flavors. But unfortunately, the responders are few. So I can only share my socket programming tips in Solaris at here (the Chinese version can be found there):1. Use the following link options: "-lresolv -lnsl -lsocket";2. Solaris doesn't provide socket options: SO_SNDTIMEO and SO_RCVTIMEO(Why does Solaris OS define SO_SNDTIMEO and SO_RCVTIMEO socket options in header file which actually not support by kernel?);3. In SCTP programming, must call bind() befor...

11,868 0       C SOCKET SOLARIS


  An experience of fixing a memory-corruption bug

During the last 4 months, I was disturbed by a memory-corruption bug, and this bug will cause program crash. Until last Monday, I found the root cause and fixed it. This debug process is a difficult but memorable experience, so I will share it in this article. My program works as a SMS Hub. When it receives a SMS, it will allocate a structure in heap memory like this:typedef struct{ ...... int *a[8]; ......} info;After processing the SMS, the program will free the memory, and send the SMS to the next Hub or Operator.  Since last November, the program will crash som...

9,016 0       C UNIX DEBUG SOLARIS MULTI-THREAD


  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,370 5       C ANALYSIS CODE REVIEW HEARTBLEED