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

 C


  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,591 0       C


  C Preprocessor Hell

Lisp programmers should stop reading right now because they'll likely suffer severe injury of the jaw muscles as they laugh themselves silly at how hard it is to do some things in C. The C language has a pre-processor (typically called cpp) that is both infuriating and powerful. How powerful is usually best described as 'just too little' and it has happened more than once that I found myself almost - but not quite - able to do what I wanted to do.The frustration can run very deep at times like these. Recently I had another battle with the C pre-processor to write a set of macros to accompl...

5,732 0       C PREPROCESSOR LISP HELL


  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,298 0       C SOLARIS


  Converting Decimal Fractions to Binary

Converting Decimal Fractions to BinaryIn the text proper, we saw how to convert the decimal number 14.75 to a binary representation. In this instance, we \"eyeballed\" the fractional part of the binary expansion; 3/4 is obviously 1/2 + 1/4. While this worked for this particular example, we\'ll need a more systematic approach for less obvious cases.In fact, there is a simple, step-by-step method for computing the binary expansion on the right-hand side of the point. We will illustrate the method by converting the decimal value .625 to a binary representation..Step 1: Begin with the decimal frac...

4,655 0       DECIMAL FRACTIONAL BINARY


  Function Pointers in C are Underrated

The function pointer in C is, in my opinion, one of the most ignored gems of the language. It’s the kind of feature you rarely need, and then suddenly, one day, you find yourself in dire need of it, as evidenced by the real-life use-case below.If you don’t know what a function pointer is in the first place, here’s the meat of it: it gives you the ability to pass a function around like a normal variable. If you know Python / Ruby / Lisp, you might know it by the name ‘lambda’, or if you come from a JavaScript background, you might’ve used it under the na...

4,349 0       C ANALYSIS POINTER


  A Toast to C

At Cloudmetrx, we use a lot of C. So given the recent passing of UNIX legend Dennis Ritchie, the creator of the C language, we think a toast to C is only fitting.Our extensive reliance on C is especially unusual considering the other languages in our stack – Clojure, Node.js, and other hipster platforms. We aren't predisposed to using older, "venerated" technologies simply because they're older and venerated. But when it comes to high-performant computation, there's just nothing like C. Some will claim Java, but those people are incorrect. There's nothing like C.In my opinion, the reaso...

4,207 0       C POPULARITY DENNIS RITCHIE UNIX TOAST C LANGUAGE


  Getting started with C++ TR1 regular expressions

Overview This article is written for the benefit of someone familiar with regular expressions but not with the use of regular expressions in C++ via the TR1 (C++ Standards Committee Technical Report 1) extensions. Comparisons will be made with Perl for those familiar with Perl, though no knowledge of Perl is required. The focus is not on the syntax of regular expressions per se but rather how to use regular expressions to search for patterns and make replacements. Support for TR1 extensions in Visual Studio 2008 is added as a feature pack. It is also included in Visual Studio 2010. Other im...

4,129 0       EXTENSION REGULAR EXPRESSION REPLACE TR1


  How big is sizeof structure?

First let's see the codes of a structure:struct node{ int a; int b;};Question : What's sizeof(node)? The answer is very simple, on a 32 bit machine, an int will take 4 bytes and two ints will take 8 bytes. So sizeof(node) is 8.The answer for the above codes is 8, then how about the following structure:struct node{ char a; int b;};Question : Then what's sizeof(node) now? int takes 4 bytes, char takes 1 bytes, is the answer 5?Now the answer may not be 5, on some machines, the answer is 8. Why?In fact, this is not the problem of the language. You will not find why in ANSI C. Even you ...

3,747 0       DATA STRUCTURE ALIGNMENT PACK