Tuesday, 16 July 2019

Is an Array in C a Pointer?

In some programming languages, arrays are high-level ‘objects’ and the programmer can think of them simply as ordered lists. In C, you have to deal with arrays ‘as they really are’ because C doesn’t try to hide what is going on ‘close to the metal’. One of the common misconceptions (which I’ve read so many times in books and on web sites that I almost started to believe it was true!) is that array ‘variables’ are ‘special types of pointer’. Well, they aren’t. Not only that, array identifiers aren’t even variables.

Let me explain. Let’s assume you’ve declared an array of chars (C’s version of a string)  called str1 and a pointer to an array of chars, str2:

    char str1[] = "Hello";
    char *str2 = "Goodbye";

An array and an address (in C) are equivalent. So str1 is the address at which the array of characters in the string "Hello" are stored. But str2 is a pointer whose value is the address of the string "Goodbye".

In fact, str1 isn’t a variable because its value (the address of an array) cannot be changed. The contents of the array – its individual elements – can be changed. The address of the array, however, cannot. That is why I prefer to call str1 an array ‘identifier’, though many people would call it, somewhat inaccurately, an ‘array variable’.

But, wait a moment. If the value of an array identifier such as char str1[] and the value of a pointer variable such as char *str2 are both addresses, aren’t str1 and str2 both pointers?

No, they are not.

It is an essential feature of a variable that its value can be changed. The value of an array identifier cannot be changed. What’s more, a pointer variable occupies one address; its value can be set to point to different addresses. But an array identifier and its address are one and the same thing. How can that be?

You have to understand what happens during compilation. When your program is compiled, the array identifier, str1, is replaced by the address of the array. That address cannot be changed when your program is run. But str2 is a pointer variable with its own address. Its value (the address of an array) can change if new addresses are assigned to the pointer variable.

If you need to know more about the mysteries of pointers, arrays and addresses in C, I have a book that explains everything (with all the source code examples for you to download). It’s called The Little Book Of Pointers and it’s available as a paperback or eBook from Amazon (US), from Amazon (UK) and other Amazon stores worldwide.

Friday, 12 July 2019

MAGIX PopUp Ads – how to get rid of them

They are like a virus. They infect your computer and make a damn’ nuisance of themselves by popping up adverts, special offers, upgrade deals and, well, more adverts… Upgrade MovieStudio, Buy Sounds for ACID, Download Stuff for VEGAS, Install Junk I really don’t want for MAGIX Music Maker. The damned adverts pop up at the bottom of the screen almost every time I boot up the computer. If there was ever a way to make the customer hate your products, this is it!

Does anyone really want to see these ads popping up on their PC every day???
Actually, I rather like many MAGIX products. But their persistent, irritating, spammy popup adverts are doing their best to make me change my opinion.

Another day, another ad!!!
But how do I get rid of them? I couldn’t see an option anywhere to “Disable our Spamware”. I ended up having to Google for help. I eventually found that I have to uninstall a piece of junkware called MAGIX Connect. Go to Settings, Apps, MAGIX Connect, Uninstall.

Oh joy! Gone at last!
Hurrah! Now the blasted adverts are gone. What I find truly mysterious about this is that MAGIX can’t see the obvious truth that, far from promoting its software, these nasty, trashy, annoying popups are about the worst sort of bad publicity they could possibly have. As I said, their software is generally good. But as for their Spamware…!!!!

Sunday, 7 July 2019

Learn C Programming, Pointers and Recursion

I’m pleased to announce the launch of Bitwise Books! We’ve been working away at this for most of the last year. Our aim is to publish a range of tightly-focused programming books that explain just what you really need to know without any padding.


The series is called The Little Book Of… and our first three titles are:

The Little Book Of C Programming
Amazon.com
Amazon.co.uk

The Little Book Of Pointers
Amazon.com
Amazon.co.uk

The Little Book Of Recursion
Amazon.com
Amazon.co.uk

In addition, we have created a series of free programming guides called A Really Simple Guide To… These include A Really Simple Guide To Object Orientation, C IDEs and Pointers. To can get the guides delivered straight to your inbox (no purchase necessary) from the Bitwise Books site.

We’ll be announcing more Really Simple Guides and Little Books Of (various programming topics) soon.

Monday, 1 July 2019

Free File Sync and Backup


I live in dread that my PC will suddenly cease to function and I’ll lose all my work. In spite of taking daily incremental backups (I use Macrium Reflect for those), what I would really like is to have complete, uncompressed, unarchived, ready-to-run copies of all my data files on a second PC. So if PC Number One goes wrong, I can just switch over to PC Number Two and carry on working. As I have a lot of data – video files for my courses, document files for my books, plus images, program code and all sorts of other stuff, I really, really don’t want to lose anything.

So recently I’ve been using a rather fine file-copying program called FreeFileSync. This lets you synchronize copies of folders and sub-folders. That means that you can, in principle, have two complete copies of your data and let FreeFileSync work out which are the most recent copies and then update any out-of-date files by copying the newer versions over them. In that way you could work on the same data on two PCs and let FreeFileSync synchronize them.

With FreeFileSync you can create named backup sets and synchronize groups of subfolders across two computers.
In fact, my requirements are a bit simpler. I want one ‘working set’ of data and one copied set of data. So instead of synchronizing in ‘two directions’, both to and from my two PCs, I just want it to keep a ‘backup copy’ on PC Two updated with any changes I make to the files on PC One.

It does a pretty good job of this. My initial backup (340Gb of data over 131,549 files) took over ten and a half hours to complete. Thereafter, however, it only copies any changed files. To do that it does a file comparison which takes just a few minutes and a file copy which again takes seconds or minutes. If you need to maintain multiple copies of your files, I recommend that you try out FreeFileSync. My main criticism, so far, is that it doesn’t have a built-in scheduler. So if you need to do automatic timed backups, you are going to have to do a bit of extra work using the Windows Task Scheduler.

My initial backup was huge as this chart (which shows backup progress) proves. Subsequent backups are much smaller and faster.
Even so, this is a useful tool to have. After all, disaster has a habit of striking just when you least expect it. And you really can’t have too many backups!

Tuesday, 21 May 2019

In Search Of The Perfect Keyboard

Oh, how I dream of the old IBM keyboard!


An original 1981 IBM keyboard
I began using PCs way back in the early ’80s. Technology has advanced greatly since then. But the one thing that was better then than now was the keyboard. The IBM keyboard set the standard. A good, solid click and keys that never faded. The keyboard of my old Olivetti M24 was excellent too.

Most keyboards these days are flimsy things. And worst of all, the letters on the keys keep fading away. They do for me anyway. Maybe that’s because I am a heavy keyboard user – I write or program for many hours every day. Or maybe it’s because (as I’ve heard some people claim) I am one of those people whose skin acidity happens to be detrimental to keyboard keys.

Anyway, recently I decided the time had come to replace an old keyboard (a VicTop which cost £29 in 2017 – this model is no longer available but various other Chinese-made ‘mechanical’ keyboards appear to be very similar). Although it was a cheap keyboard, it is remarkably solid, has a lovely ‘clicky’ feel and in the couple of years I’ve had it, has been absolutely reliable. But some of its keys were wearing so badly that I could no longer see which was which.

Ideally I wanted a keyboard with ‘doubleshot’ keys. A doubleshot key is one that is constructed from two layers of plastic. One layer contains the raised shape of a character such as ‘A’. The other layer is, in effect, poured on top of this to form the rest of the key surface. So if ‘A’ was moulded in black plastic and this was covered with white plastic, you end up with a black key with the letter ‘A’ in running through it in white (like the words through a stick of British seaside rock).

Once upon a time, every half-way decent keyboard had doubleshot keys. These days most keyboards just have the letters  ‘painted’ or ‘stuck’ onto the key, which is why they wear off so easily. Some slightly more resilient keys use ‘laser etching’ which means that the characters are etched into a small groove. These won’t actually wear off completely but they can fade.

Filco Majestouch Ninja
It turns out that keyboards with doubleshot keys are now as rare as hen’s teeth. So eventually I settled for an alternative: a keyboard with no letters at all on the top surfaces (so they can’t wear off!) but instead with letters on the front surface – the vertical surface that faces you as you sit at the keyboard. This was the Filco Majestouch Ninja. It’s quite an expensive keyboard (£130 inc. VAT) but it has a nice solid click (look for Cherry Blue keys if a good click is what you are after) and, while it does take a while to get used to the blank key tops, after a couple of days I barely noticed the difference.

VicTop keyboard with its original keys
This left me with my trusty old VicTop keyboard which, in spite of its faded keys, I was reluctant to throw away. I decided to have a go at refurbishing it by replacing the faded keys with doubleshot ones. Bizarrely, even though it’s hard to find a keyboard with doubleshot keys already fitted, replacement doubleshot keys are easy to find. I bought some keys in the good old Olivetti colours (at about £38 inc VAT these cost more than the keyboard itself but much less than a new Ninja keyboard).

VicTop keyboard with replacement Olivetti-style doubleshot keys
It took me about an hour to replace the old keys. And my refurbished keyboard is now pretty close to ideal. I don’t know whether my new Ninja keyboard will outlast my cheap refurbished keyboard. What I can say is that both keyboards are now as near to perfect as I could hope for.

Though I still dream of an old IBM keyboard…

Friday, 17 May 2019

RIP Ken Musgrave - Long Live Mojoworld!


Dr. Forest Kenton Musgrave (aka 'Doc Mojo') was one of the great figures in the evolution of computer digital art, particularly landscape creation through fractal geometry. I still have a (now rare) boxed copy of his wonderful Mojoworld software, which lets you generate hugely complex fractal planets and then send a virtual camera around it looking for interesting views to render as still images or animations. Sadly, Ken Musgrave died (far too young!) last December. Way back 2001, I interviewed him. When Digital Art Live Magazine asked if they could reprint that interview as a tribute, I was very pleased to agree.

You can read the interview online here: https://issuu.com/tosk/docs/digital_art_live_issue_39_20190504

Or go to the Digital Art Live web site here: https://digitalartlive.com/digital-art-live-magazine/

Wednesday, 17 April 2019

Zork Source Code Online - the Holy Grail of Text Adventures!

Anyone who knows me (or reads my articles or follows my programming courses) can't fail to have noticed that I am passionate about text adventures. In fact, it was the old Infocom text adventures such as Zork, Starcross and Trinity that first got me interested in programming, long, long ago. So interested, in fact, that I wrote my own adventure, The Golden Wombat Of Destiny.

The one thing I never expected to see was the source code of the classic Infocom games. Well, today, that all changed. Because the code is now online. I don't honestly know if this is in the public domain or not. I think that theoretically Activision 'owns' the code but clearly the company is doing nothing at all with it. That being so, this great treasure of programming really should be available to inspire and instruct coders old and new. You may need to be dedicated, however. This is not written in any mainstream language such as Java or C. It's written in ZIL (and MDL) which are variants of LISP.

More information here: