Programming

Array Indexing in C

I found this interesting thing about array indexing in C somewhere in the web:
Suppose that “a” is an array. Then, a[5] and 5[a] are quivallent. Both are interpreted as *(5 + a) or *(a + 5) which is the same :)
Also: “Hello World”[3] and 3["Hello World"] are the same. Try and C ;)

Post to Twitter Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to Ping.fm Post to Reddit Post to StumbleUpon

Tags: ,

Wednesday, January 6th, 2010 Programming No Comments

Tools to Improve the Quality of Your Code

Just found a nice link at Wikipedia with a collection of tools to help analyzing the quality of your code.

One interesting one is PMD (for Java), which is opensource. It statically analyses your code and alerts for potential problems.

For C, there is splint (opensource as well), which statically analyses your code for potential coding mistakes and security vulnerabilities.

The full list at Wikipedia is here.

Another great tool, which is not directly related to the above, is Valgrind. While the above statically analyze your code (i.e., they find potential problems by “just looking at the code”), Valgrind is a tool for dynamic analysis, which means, it analyses the code by monitoring the way it runs. It can report possible memory leaks, possible deadlooks, and many other information. (The full tool suite description can be found here). The output of Valgrind is not very easy to read, but with a little practice one can feel more comfortable with it.

There is also a list of tools for dynamic analysis at Wikipedia. It’s located here and may be worths a glance.

Enjoy coding ;)

Post to Twitter Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to Ping.fm Post to Reddit Post to StumbleUpon

Tags: ,

Saturday, September 26th, 2009 Programming No Comments

A Bash Script to Convert brainfuck Code Into C

Brainfuck is a minimalist Turing Complete language. You can read about it here.

The following bash script takes a file with brainfuck code (legal characters are >< ,.+-[] any other characters are ignored), and generates its C equivalent code, which can then be compiled with a C compiler and executed.

The output of this script lacks indentation. If you insist on having the C code indented you can achieve this by passing the output through a pipe to “indent”, “astyle” or similar programs.

The script should be called in the following way:

./bf.sh code.bf > code.c

Where code.bf is the file containing the brainfuck code.

› Continue reading

Post to Twitter Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to Ping.fm Post to Reddit Post to StumbleUpon

Tags: , , ,

Sunday, June 14th, 2009 Programming No Comments

Share Code Snippets Easily From the Command Line

This is a great tip I found at commandlinefu to easily share code snippets write from the command line.

First, you may want to add this to your aliases file:

1
alias share='curl -F "sprunge=<-" http://sprunge.us | xclip'

(If you don’t have the xclip program, you can easily install it from your package manager.)

Now, say that you have a c program named “hello.c”, to share it, type this (after reloading your aliases file of course):

cat hello.c | share

Now, the code is already in the internet, and the URL is in your clipboard. Go to firefox and click the middle mouse button in the URI area. You’ll see a URL similar to this:

http://sprunge.us/BaFS



To view the code with syntax highlighting and line numbers, just append “?c? (or “?lang” where ‘lang’ is the relevant programming language). So the final URL should look like this:

http://sprunge.us/BaFS?c

Enjoy ;)

Post to Twitter Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to Ping.fm Post to Reddit Post to StumbleUpon

Tags: , , ,

Saturday, June 13th, 2009 Programming No Comments

Sending Emails with Matlab

This method is (as far as I know) not found in the official Matlab’s documentation.  I found it a long time ago somewhere in the internet (don’t remember where, sorry). It’s intended for sending Emails using Matlab.

In order to use it, you should have an Email account which supports SMTP (eg. Gmail). This account will be the account we’re sending the messages through.

The script assumes you’re using Gmail, but it can be easily modified to use other Email suppliers (are there any?)

› Continue reading

Post to Twitter Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to Ping.fm Post to Reddit Post to StumbleUpon

Tags: ,

Saturday, January 31st, 2009 Programming 4 Comments

How to Convert a Number into a String in C++

I found a few ways to convert a number into C++, some of them are C style (like using sprintf), and some are ugly (i.e non-standard, like using itoa), and there some nice way which uses string streams to achieve this.

Where going to define and implement a function called Stringify, which accepts an integer and returns a string (this can be extended to accept any numeric value).

› Continue reading

Post to Twitter Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to Ping.fm Post to Reddit Post to StumbleUpon

Tags: ,

Friday, January 23rd, 2009 Programming 2 Comments

The Power of Polymorphism (Video)

This video is part of “The Clean Code Talks” series, which is itself a part of the great “Google TechTalks”.

The video shows the strength of using polymorphism instead of switch statements and “if” conditionals, to get a much cleaner cleaner code, allowing it to be more readable, testable and maintainable.

One of the best videos I watched in this series.

› Continue reading

Post to Twitter Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to Ping.fm Post to Reddit Post to StumbleUpon

Tags: ,

Monday, December 15th, 2008 Programming No Comments

Easily Create Code Snippets with Bonetree Box

Update: Looks like the link is not valid anymore :(    Anyhow, one always can use http://pastebin.com ;)

Have you ever needed to show a code to a friend? If yes, I have no doubt that you will love Bonetree Box.

This web tool has a very simple and well-designed interface, and working with it is with no doubt a pleasant experience.

The tool has support for a set of popular programming languages, such as C, C++, Bash and more (I believe that this set will be extended over time), and allows you to create a syntax highlighted code snippets with zero effort.

› Continue reading

Post to Twitter Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to Ping.fm Post to Reddit Post to StumbleUpon

Tags:

Saturday, November 29th, 2008 Programming 1 Comment

How to Declare an Array of Strings in C

Ok, I know this is not a big deal, I just hate to deal with strings in C, so I’ll put the code here so I can copy-paste-modify whenever I need to do such things.

Purpose: declare an array of strings.

There are two cases here:

› Continue reading

Post to Twitter Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to Ping.fm Post to Reddit Post to StumbleUpon

Tags:

Friday, November 28th, 2008 Programming No Comments

Using Macros to Print Debug Messages in C

I have to confess: It’s my first time using macros for debug, I used to just add printf-s when developing and remove them when the code is ready – Which is and ugly and very unprofessional in my opinion.

So, I decided to start caring about how my code looks, even in development stage. Here how I use macros for debug messages. (I needed the help of a friend to get this work).

first of all, define this:

› Continue reading

Post to Twitter Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to Ping.fm Post to Reddit Post to StumbleUpon

Tags: , ,

Saturday, November 22nd, 2008 Programming 5 Comments
my email
Already a member?
Login
Login using Facebook:
Last visitors
my photo
Hi,
My name is Amir Watad. I have a BSc. in biomedical engineering from The Biomedical Engineering school , Technion , Israel, and am currently studying for a BSc. in electrical engineering at The Electrical Engineering school , Technion , Israel.
I work at the verification dept. in Mellanox Technologies Ltd.
I love Linux, the Command Line and the OpenSource Community.
I used to write Poems (Arabic) when I was able to find time for this.
March 2010
S M T W T F S
« Jan    
 123456
78910111213
14151617181920
21222324252627
28293031  
Opensource Logo
SEO Powered by Platinum SEO from Techblissonline

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.