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

 C


  Faster than C

Judging the performance of programming languages,usually C is called the leader,though Fortran is often faster.New programming languages commonly use C as their referenceand they are really proud to be only so much slower than C.Few language designer try to beat C.What does it take for a language to be faster than C?Better Aliasing InformationAliasing describes the fact that two references might point to the same memory location.For example, consider the canonical memory copy:void* memcopy(void* dst, const void* src, size_t count) { while (count--) *dst++ = *src++; return dst;}Depending on...

3,307 1       C PERFORMANCE SPEED FORTRAN CRITERIA


  Smuggling data in pointers

While reading up on The ABA Problem I came across a fantastic hack.  The ABA problem, in a nutshell, results from the inability to atomically access both a pointer and a "marked" bit at the same time (read the wikipedia page).  One fun, but very hackish solution is to "smuggle" data in a pointer.  Example:#include "stdio.h"void * smuggle(void * ptr, int value){  return (void *)( (long long)ptr | (value & 3) );}int recoverData(void * ptr){  return (long long)ptr & 3;}void * recoverPointer(void * ptr){  return (void *)( (long long)ptr & (~3) );}int main(...

3,072 0       C POINTER BIT DATA ATOMIC SMUGGLE


  Taking C Seriously

Dennis Ritchie, a co-creator of Unix and C, passed away a few weeks ago, and was honored with many online tributes this weekend for a Dennis Ritchie Day advocated by Tim O’Reilly.It should hardly be necessary to state the importance of Ritchie’s work. C is the #2 language in use today according to the TIOBE rankings (which, while criticized in some quarters, are at least the best system we currently have for gauging such things). In fact, TIOBE’s preface to the October 2011 rankings predicted that a slow but consistent decline in Java will likely m...

2,963 0       C EFFICIENCY DENNIS RITCHIE MEMORIZATION


  The "C is Efficient" Language Fallacy

I came across an article yesterday about programming languages, which hit on oneof my major peeves, so I can't resist responding. The article is at greythumb.org,and it's called Programmer's rant: what should and should not be added to C/C++.It's a variation on the extremely common belief that C and C++ are the best languages to use when you need code to run fast. They're not. They're good at things that need to get very close to the hardware - not in the efficiency sense, but in the sense of needing to be able to fairly directly munge the stack, address specific hardware registers, etc. But...

2,948 0       C EVOLVEMENT GCC FALLACY


  printf("goodbye, Dennis");

Dennis Ritchie, a father of modern computing, died on October 8th, aged 70EVERY time you tap an iSomething, you are touching a little piece of Steve Jobs. His singular vision shaped the products Apple has conjured up, especially over the last 14 years, after Jobs returned to the helm of the company he had founded. Jobs's death in October resembled the passing of a major religious figure. But all of his technological miracles, along with a billion others sold by Apple's competitors, would be merely pretty receptacles were it not for Dennis Ritchie. It is to him that they owe their digital souls...

2,888 0       MEMORY C DENNIS RITCHIE FATHER OF C


  C/C++ Pointer Declaration Syntax – It makes sense!

I never really liked the way pointers are declared in C/C++:int *a, *b, *c; // a, b and c are pointers to intThe reason is that I am used to reading variable declarations as MyType myVar1, myVar2, myVar3; and I always read “int*” as the type “integer pointer”. I therefore wanted the followingint* a, b, c; // a is a pointer to int, b and c are intsto mean that a, b and c all were of type int*, i.e. pointers to int. and I therefore found it slightly annoying to repeat the asterisk for every variable. This also meant that the symbol * had two sligh...

2,806 0       C POINTER DECLARATION ATTEMPT


  Pointers, arrays, and string literals

A recently posted question on Stack Overflow highlighted a common misconception about the role of pointers and arrays held by many programmers learning C.The confusion stems from a misunderstanding concerning the role of pointers and strings in C. A pointer is an address in memory. It often points to an index in an array, such as in the function strtoupper in the following code:void strtoupper(char *str){ if (str) { // null ptr check, courtesy of Michael while (*str != '\0') { // destructively modify the contents at the current pointer location ...

2,791 0       CHAR POINTER INITIALIZATION LITERAL CANN


  template function in class in C++

We can define template function in a class, but one thing we should pay attention to is that the member function template definition (in addition to the declaration) should be in the header file, not the cpp, though it does not have to be in the body of the class declaration itself.Example //Sorter.h#pragma onceclass Sorter{public:    Sorter(void);    ~Sorter(void);    template <class type> static void qsort(type arr[],int start,int end);};template <class type> static void Sorter::qsort(type arr[],int start,int end){    in...

2,670 0       C++ TEMPLATE FUNCTION CLASS DEFINITION D