Tag Archive for gvim

How to do stupid things with “hello_world” and owncloud …

The Raspberry Pi is not meant to be a powerful beast but I’m going to learn to code on it just because I can. I’m also going to do daft things on purpose as well as inadvertently. Soooo here goes …

From windows log into owncloud by typing http://youraddress.org into the Chrome browser address bar. When the pop-up login box appears enter user & password details. Within the owncloud www browser interface click on new > folder and make the ‘cprog’ folder. Next, open a LXTerminal on the pi and type vim then type to change into command entry mode. Then type cd /home/user/owncloud/cprog and then type Esc and then to start inserting code.

Alternatively I could have just done a cd to the same directory and typed Esc type  :  type  type hello to create the file hello

Time to stop waffling and just start typing. Enter the following code


type Esc type  :  type  type  hello to save the file hello

type Esc type  :  type  type  hello to save the file hello

type make hello

This fails with the following message make: Nothing to be done for ‘hello’

The crux of the matter is whether make has a rule to build the target or not. If there is no rule for the target, but the target exists, then gmake will say, “Nothing to be done“, as in, “I don’t know how to update this thing, but it already exists, so I guess there’s nothing to be done.”

It I tell make that hello is a c file then it knows what to do

type mv hello hello.c

type make hello

Compiles but takes 11 seconds! Shocked, I do it again and this time it fails with the following message make: ‘hello’ is up to date

If there is a rule, but the target is already up-to-date, then gmake will say, “is up to date“, as in, “I do have instructions for updating this thing, but it appears to already be up-to-date, so I’m not going to do anything.”

Finally, I do it in my pi home directory In my home directory and it takes a second.

What have I learned? Firstly that I quite enjoy wasting time doing pointless things rather than being productive. Secondly, owncloud is slow and coding in an owncloud directory is an excellent way to waste a bit of time. Thirdly, ‘make’ is not stupid but programmers sometimes are. Fourthly, I still like nano better than vim

setup raspberry pi for c programming

I’m making notes in blog form as I do the lcthw course

build-essential sudo apt-get install build-essential To put it simply, if someone or some package needs to install a C/C++ compiler, then they need to install, Debian “build-essential” – it gives you gcc, make & other useful stuff. Check the documentation: Here!

valgrind sudo apt-get install valgrind (norse – main entrance to Valhalla) is a programming tool for memory debugging, memory leak detection, thread debugging and code profiling. Initially developed and used on x86 but as of version 3, now for most architectures, including ARM e.g., the Pi. It allows you to run your program inside Valgrind’s own environment where it monitors memory usage such as calls to malloc and free (or new and delete in C++). If you use uninitialized memory, write beyond the end of an array, or forget to free a pointer, Valgrind can detect it. This is very useful as these are particularly common problems.

Ctags sudo apt-get install ctags NB a lot of times, the best documentation for a system is the source code for it. Usually there’s documentation near to where methods, functions, classes, variables, parameters etc are defined. It’s all very useful. Ctags uncovers this information elsewhere in the active file or another file. Knowing how to get to such important places matters. To help, Vim uses a tags file that lists each word you are likely to want, and their locations (file path and line number). Each wanted word is known as a “tag” and jumping around in code is done with them. Tags are created from function names, function definitions, global variables etc. When editing your code, or someone else’s code ctags makes a huge difference in how productive you are and even in what you can figure out how to do. See this tutorial 

Ack sudo apt-get install is like grep a text search tool designed for programmers with large trees of heterogeneous source code. It searches directories recursively by default while skipping usually undesired directories and files such as version control directories, backup files, binary files etc. Some of its other capabilities and features include highlighting of search results, filtering files without searching them, and using real Perl regular expressions. Ack is often used in place of grep and is marketed as ‘better than grep’ see this post and also this post the documentation is here

vim-gtk sudo apt-get install vim-gtk for the ‘lite’ version of vim-gnome. Both compile to Gvim using different dependencies but vim-gtk does so without the GNOME libraries. Gvim is the GUI version of vim which is a superset of vi see this post

Finally, I like nano because it’s easy, so why bother investing time & energy to learn vim? The reason I’m going to learn vim is because ‘serious coders’ use it and it isn’t emacs … read this and this for tips about coding tools

Syntastic (to do list) is a syntax checking plugin that runs files through external syntax checkers and displays any resulting errors to the user. Read about it here and here and see vim-syntastic on google groups