[Book Review] Understanding and Using C Pointers

@book{reese,
    author    = "Richard Reese",
    title     = "Understanding and Using C Pointers",
    edition   = "First",
    year      = "2013",
    publisher = "O'Reilly",
}

Thanks to the Mauritius Software Craftmanship Community (MSCC), i got access to the book “Understanding and Using C Pointers” by Richard Reese. I read only the first 3 chapters till now. It’s like really lots to disgest.

cpointers

I got interested in the book because i am doing my BSc final year project using C++. C/C++ programmers usually use pointers a lot. Reese says

“a solid understanding of pointers and the ability to effectively use them separates a novice C programmer from a more experienced one.”

Unfortunately the book doesn’t illustrate the difference between a pointer and a “normal” variable. Having read the first 3 chapters still makes me wondering when should i use pointers and even is it really worth it?

In the first year at university in python class, my lecturer mentioned that arrays are passed by reference to functions in almost all programming language.

void change(int array[], int pos,int newval){
    array[pos] = newval;
}

int main()
{
    int x[] = {1,2,3};
    change(x,2,5);
    std::cout << x[2] << endl;
    return 0;
}


5 will be outputed on the screen i.e. x was passed by reference. What advantage would i get for using pointer notation instead?

I find the book too hard containing too much information for beginners. I'd recommend the book to people who already have a basic knowledge of pointers. The book will improve your pointer skills with "best practices" so that you become really proficient in pointers. 🙂

The book doesn't illustration in Object Oriented Programming. I guess that is because C doesn't support OOP.

Conclusion

- Cannot be used as "introduction" to pointers to newbies
- If you're already using pointers, do read the book. It'll make you become a pointer guru for sure!

Install WebIOPi on Arch Raspberry Pi

Raspbian decided to include some Oracle software into the main OS which no one cares. I had to switch to Arch to be able to continue to use my 2GB card.

webiopiarch1

WebIOPi was developped and tested on Raspbian. Here’s how to make it work in Arch.

We install the dependencies first:-

# pacman -S python
# pacman -S python-py
# pacman -S python-setuptools
# pacman -S gcc

Now we follow the official WebIOPi documentation

# wget http://webiopi.googlecode.com/files/WebIOPi-0.6.0.tar.gz
# tar xvzf WebIOPi-0.6.0.tar.gz
# cd WebIOPi-0.6.0
# ./setup.sh

To start it, run

# webiopi

You shall be able to access it through your browser http://192.168.1.x:8000

P.S. I wrote this guide after having done it. If i missed a step please inform me.

Threading in C++11

Threading is sooo easy in C++11. It’s done 1 single line :3


thread t(&MeraClass::sayHi,this,"Nayar");

That’s it. Use t.join() anywhere you want it to complete 😀

The first argument is the name of the function or method you want to call. Since i mostly code using Object Oriented Programming (OOP), i need to specify the class name then pass the object from which i’m creating the thread. Here could be the class:-


using namespace std;
class MeraClass {

public:
   MeraClass(){
       thread t(&MeraClass::sayHi,this,"Nayar");
       t.join();
   }

   void sayHi(string name){
        cout << "Hi "<< name <<endl;
   }
};

Hey Java, BURN!!!! 3:)

Cross-Platform Scripting on Windows and Linux

I was kinda amazed at how well my .sh script on Linux would work perfectly on Windows 7.

Firstly, i had written a script to clone my dissertation files using git. I have a file named “cloner.sh”


#!/bin/sh

git clone git@example.com:project1.git
git clone git@example.com:project2.git
git clone git@example.com:project3.git

I just double-click on it from Windows 7 and my projects get cloned ASAP. On Linux, i had to mark it as executable before it would run.

I was more amazed when i tried to write a script for compiling our report on LaTex. I installed TeXworks but to compile the project we have to do about 6 -8 clicks. I wrote a compilation script and named the file as “compiler.sh”


#!/bin/sh

pdflatex main
bibtex main
pdflatex main
pdflatex main

My friend on Windows 7 pulled the file, double clicked on it. And lo! The PDF was generated correctly. It even auto downloaded missing packages as if it were run from TeXworks. Awesome! (Psst. The Linux one doesn’t do it on the fly -_-)

I added some lines to clean the mess the compilation process usually leaves

rm *.aux
rm *.bbl
rm *.blg
rm *.lof
rm *.log
rm *.lot
rm *.toc

Once again, magic! The auto-generated files were swept away.

But how is that possible?
Does Windows also use the same commands as Linux does?

I managed to get a screenshot of the window that popups for few seconds to display the output. Git also shows here. Weird nan?



I guess the “Linux” environment came along when i installed Git bash on my PC and my friend’s. Anyways, i don’t have much time to know how it just works. I’m just happy that it’s working for me and my mate 😀