vote up
0
vote down

Why can you write arr[n] == n[arr] in C ?

Try the following program in C : #include <stdio.h> int main () { int arr[] = {42}; printf("%d", arr[0] == 0[arr]); return 0; } The above program prints out 1...ie, true. But why...?Well the reason the above works is because of how arrays are
tags: c
Feb 27 2010 07:11 AM
vote up
0
vote down

Compiler code generation: just flatten the tree

I spent some time tonight working on the compiler I am writing for my own education. I started this project while only understanding bits and pieces of what it takes to write a compiler, but I am quickly learning more. Various texts on compilers start
Feb 09 2010 04:41 PM
vote up
0
vote down

Genie: Write Python-like code that runs as fast as pure C

There is an article on the Postabon Blog titled “Make Lisp 15x faster than Python or 4x faster than Java.” In his benchmark, which is a tightly nested loop doing some trigonometric calculations, he achieves speed similar to Java with
Feb 03 2010 04:47 PM
vote up
0
vote down

Two postfix operations redux: sequence points

Describes sequence points and the postincrement operator in C, contrasts with the Java language, and notes the expressions in Python that unfortunately look like preincrement/predecrement.
 
cdleary
Jan 11 2010 12:58 PM
vote up
0
vote down

Two postfix operations redux: sequence points

Describes sequence points and the postincrement operator in C, contrasts with the Java language, and notes the expressions in Python that unfortunately look like preincrement/predecrement.
 
cdleary
Jan 11 2010 03:34 AM
vote up
0
vote down

Debugging in Linux with advanced IDE's

This took me a while to figure out. I have been trying out several different IDE's for Linux C development (KDevelop, Code::Blocks, NetBeans) and I only managed to get debugging work like I wanted (e.g. code stepping, local variables etc) in
 
Makis
tags: c
Dec 07 2009 07:39 PM
vote up
0
vote down

malloc vs calloc vs realloc

char* malloc(sizeOf)Returns a pointer in the heap with the specified size. One major difference is that it does not initialize the memory. char* calloc(numElements, sizeOfElement)Returns a pointer in the heap with the specified size for a number of
tags: c
Dec 01 2009 02:20 PM
vote up
0
vote down

StackOverflow Awesomness

Besides all the cool Genetic Algorithms and Optimization mumbo jumbo, the always ready to strike SIGSEGVs and always-a-pleasure Python scripting, this is the coolest thing I have come across in recent times. This is a image on the Page Not Found for
 
amit
tags: code c
Nov 27 2009 04:38 PM
vote up
0
vote down

Readable vs Elegant?

I've been thinking about this for some time but there seems to be a contradiction within the software development community, an internal struggle between being clever and superior and a wanting for things to be clear but succinct.At DevDays in London,
Nov 26 2009 05:43 AM
vote up
0
vote down

Passing a pointer by reference in C

Today I needed a way to pass a pointer to an int to a function, modify the location of that pointer (via malloc) in that function, and then access the modified pointer from outside the function (from the caller). I tried to code it like such
tags: c
Nov 17 2009 10:16 PM
vote up
0
vote down

Old School Programmers

I came across a blog post by Eric Sink. It started out great. It showed the similarities between an old school Ham Radio Operator, and a C programmer. Then he made this statement. “…The C programmers actually have a
 
Jeremy
tags: opinion c
Nov 17 2009 10:52 AM
vote up
0
vote down

Number of elements in an array in C

Take the following piece of code: int main() { int nums[] = {1,2,3,4,5}; printf("Outside: %d\n",sizeof(nums) / sizeof(*nums)); f(nums); return 0; } int f(int nums[]) { printf("Inside: %d\n",sizeof(nums) / sizeof(*nums)); } Here is the output of the above
tags: c
Nov 17 2009 03:21 AM
vote up
0
vote down

PIC – Up and Run!

After a weekend of intense reading on the PIC32 architecture I finally got some code working. The PIC32 Starter Kit only comes with 3 LEDs and 3 Switches but I have never felt so much reward in seeing LEDs flashing. I wrote the following code, which
 
arthurcanal
tags: c pic32
Nov 10 2009 04:24 PM
vote up
0
vote down

Processes do not share Global Variables

In the C code above, what are the values at line 13 and 18?At line 13, the value is 30.At line 18, the value is 10.Why is this you ask? It's because the fork system call produces a new child process which does not share global variables with its parent
Nov 03 2009 07:23 PM
vote up
0
vote down

Usages and Definitions of All Operators in C

There is a list of all operators in C. Assignment Operator Arithmetic Operators Cast Operator Increment and Decrement Operators Abbreviated Assignment Operators Relational Operators Logical Operators Precedence of Operators I. Assignment Operator Equal
 
Mehmatrix
Oct 17 2009 04:07 AM
vote up
0
vote down

Unit Testing in C

I haven't written new C code since the turn of the millennium. Since then it's been almost all Java and Python. Along with Java and Python come JUnit and Python's unittest module.I've grown completely dependent on unit testing.I'm looking at some C code,
Oct 14 2009 10:02 PM
vote up
0
vote down

Quick Tip: Piping to gnuplot from C

Update, 21/10/09 :Thanks to A.K’s comment, Its “gnuplot” and not “GNU plot” Couple of things first up: gnuplot supports piping, So, echo "plot sin(x)" | gnuplot will plot the sin(x) function. However, the plot
 
amit
Oct 03 2009 07:35 PM
vote up
0
vote down
vote up
0
vote down

foreach en java.

Java 5 s’est rapproché de son jumeaux C# en rajoutant la possibilité d’attaquer les différentes entités d’une liste ou d’une collection à travers son propre “foreach” : C# : foreach(type var in arr){
Jul 16 2009 10:06 PM
vote up
0
vote down

Bit Operations

For CS351, Intro to Systems, we had to do several operations using bit operators only. These took awhile, but are pretty cool to show off. We were graded by how few operations we used to return the right values for the generated test cases, including
 
Chet
Jul 05 2009 01:01 AM
vote up
0
vote down

How Not To Use Goto In C Init Functions

There is the idea that Goto is useful in some complex init functions to make the code simpler. Such as:if (OK != doSomething()) goto cleanup;if (OK != doSomethingElse()) goto cleanup;There could dozens of functions that need to be called except if
 
Makis
tags: c
Jul 02 2009 06:22 PM
vote up
0
vote down

List.Find() : utilisation des delegates.

L’utilisation des delegates rend les recherches génériques beaucoup plus faciles: Considérons l’objet simple suivant : Public Class Person{   private string m_name;   private int m_age;     // .Net3.0 syntax only.
tags: c/c++ c
Jun 27 2009 02:32 AM
vote up
0
vote down

Sérialisation cryptée binaire en .net

Pour réutilisation : j’ai écrit une petite classe qui fait de l’encryption + sérialisation binaire. using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Runtime.Serialization.Formatters.Binary;
Jun 22 2009 04:48 AM
vote up
0
vote down

Hidden Features Of Perl, PHP, Javascript, C, C++, C#, Java, Ruby, Python, And Others [Collection Of Incredibly Useful Lists]

Introduction StackOverflow is an amazing site for coding questions. It was created by Joel Spolsky of joelonsoftware.com, Jeff Atwood of codinghorror.com, and some other incredibly smart guys who truly care about user experience. I have been a total fan
 
Artem Russakovskii
Jun 22 2009 02:08 AM
vote up
0
vote down

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.
 
Jeff
Jun 19 2009 07:22 PM
vote up
0
vote down

Language Advocacy

This article is nearly ten years old, but it still is relevant today. In a recent discussion, I mentioned to a beginning programmer that C wasn't the best language to learn the thought process behind programming. I justified this assertion by saying that
Jun 14 2009 06:50 AM
vote up
0
vote down

Tail Recursion Optimization, gcc, gdb

Debugging or even throwing optimized code in a debugger is a stupid idea, when you are trying to debug the code, that is. Not so lame, when you are trying to learn whether the optimization has actually taken place . I wanted to check whether Tail Call
 
amit
May 23 2009 12:47 PM
vote up
0
vote down

Eric Lippert on infoof()

I previously mentioned some hypothetical C# fieldof and methodof operators, which would obtain FieldInfo and MethodInfo objects, in the same way that typeof retrieves Type at runtime. Eric Lippert explains the pros and cons of a combined infoof operator,
 
Tim Robinson
tags: c
May 23 2009 12:20 AM
vote up
0
vote down

Eric Lippert on infoof()

I previously mentioned some hypothetical C# fieldof and methodof operators, which would obtain FieldInfo and MethodInfo objects, in the same way that typeof retrieves Type at runtime. Eric Lippert explains the pros and cons of a combined infoof operator,
 
Tim Robinson
tags: c
May 23 2009 12:20 AM
vote up
0
vote down

Comparing Version Numbers

Comparing version numbers is one of those operations that seems like it ought to be simple but can have a fair bit of complexity under the surface. How would you write an algorithm that gives the correct result for all of the following? 2.10 comes after
May 18 2009 12:48 AM
vote up
0
vote down

Bit twiddling: Simple O(1) membership test

Disclaimer Bit twiddling is fun. Plus, it has several advantages: It gives you a greater understanding of the nuances of the (C) language. As we all know, learning C is important. If you’re a computer engineer and have weak C-fu, then it is time,
 
Christopher Leary
Apr 08 2009 01:30 AM
vote up
0
vote down

Hello World!

I decided to write the age old Hello World program in a lot of languages that interest me. I didn’t get around to objective-c or c#. If the language was object oriented, I tried to write an OO Hello World example. I enjoyed doing this, and I hope
 
ScArcher2
Jan 23 2009 01:39 AM
vote up
0
vote down

CL-ROGUE

Over the last six months I have been porting the 1981 version of Rogue to CL. My intention was to learn the basics of CL; it's a straight port of the game. I wish I had thought of porting something sooner (especially Rogue, which I once ported to
Jun 18 2007 02:46 AM