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

 C


  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,322 0       C ANALYSIS POINTER


  Using C for a specialized data store

Pixenomics stores and transports 1.2 million pixels from the server to the client. During development we played with various methods to store and process this. Our ultimate goal was to send the entire board in under 1 second.During the stages of prototyping we used a MySQL database without thinking too much about performance. With a mere 2,000 pixels we quickly realised this wasn’t even usable as a demo. Changing the storage engine to memory was much better but still obviously unusable.The problem wasn’t to store the pixels but to retrieve all 1.2 million pixels quickly as well a...

2,560 0       C PERFORMANCE EFFICIENCY DATA STORE


  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,774 0       C POINTER DECLARATION ATTEMPT


  How Many C Programs Are There?

If I choose a size S, can you tell me how many valid C programs exist that are no larger than that size? I’m actually interested in the answer — it’ll help me make a point in a paper I’m writing. Shockingly, the Internet (or at least, the part of it that I looked at based on a few searches) does not provide a good answer.Let’s start with a few premises:Since it would be exceedingly difficult to construct the exact answer, we’re looking for a respectably tight lower bound.S is measured in bytes.Since it seems obvious that there’s an exponential n...

2,303 0       C PROGRA NUMBER STATISTIC CALCULATION


  Preprocessor magic:Default Arguments in C

This post is for programmers who like C or for one reason or another can't use anything else but C in one of their projects. The advantages of having default arguments is not something that needs convincing. It's just very nice and convenient to have them. C++ offers the ability to define them but C under the C99 standard has no way to allow it. In this post I will detail two ways I know of implementing default arguments in C. If a reader happens to know additional ways please share in the commentsSuppose we have a struct that contains some data and we want to initialize it//! The struct we wa...

12,301 0       C PREPROCESSOR DEFAULT ARGUMENTS


  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,703 0       C PREPROCESSOR LISP HELL


  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,923 0       C EVOLVEMENT GCC FALLACY


  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,732 0       C FORTRAN INTRINSIC FUNCTIONS C99 UGLY