An E(x)tern Newbie Question

I want to know how to declare a const variable in one file and access it from other files? (C++). It’s a fairly basic question, and reveals that you have to study more C++. What you want is to define a const variable at global scope. Unlike non-const variables (which are extern by default), const variables are local to the file in which they are defined. Therefore, you cannot access them from other files unless you specify that the variable is extern. For instance, if you specify extern when defining the variable

bufferSize in file1.ccextern const int bufferSize = 512;

you can access bufferSize from any other file, say, file2.cc

extern const int bufferSize; // we are using bufferSize from file1.cc

And that’s it.

hello world, C and GNU as

A thing all these programs had in common was their use of the 09h function of INT 21h for printing the “hello, world!” string. But it’s time to move forward. Now I plan to use the lovely C printf function.

GNU Head

Finally, it’s time to switch to the fabulous GNU as. We’ll forget about DEBUG for some time. Thanks DEBUG. GNU as, Gas, or the GNU Assembler, is obviously the assembler used by the GNU Project. It is part of the Binutils package, and acts as the default back-end of gcc. Gas is very powerful and can target several computer architectures. Quite a program, then. As most assemblers, Gas’ input is comprised of directives (also referred to as Pseudo Ops), comments, and of course, instructions. Instructions are very dependent on the target computer architecture. Conversely, directives tend to be relatively homogeneous.

1 Syntax

Originally, this assembler only accepted the AT&T assembler syntax, even for the Intel x86 and x86-64 architectures. The AT&T syntax is different to the one included in most Intel references. There are several differences, the most memorable being that two-operand instructions have the source and destinations in the opposite order. For example, instruction mov ax, bx would be expressed in AT&T syntax as movw %bx, %ax, i.e., the rightmost operand is the destination, and the leftmost one is the source. Other distinction is that register names used as operands must be preceded by a percent (%) sign. However, since version 2.10, Gas supports Intel syntax by means of the .intel_syntax directive. But in the following we’ll be using AT&T syntax.

Continue reading “hello world, C and GNU as”

Programmers from the Wild West

Analysis, Design, and related topics are for sissies, and for allowing professors of Computer Science who are bad at mathematics to make a living. SDLC is a pony. Cowboys ride horses.

We all know what happens when a project’s deadline is not met. Besides firing someone, hard, dry heroes appear. Lonesome, ruthless and distrustful heroes which brings the peace only revolvers can conquer. Sometimes, the guys with the money hire them as the ultimate saviors: they have bothered to come here, from the farthest west, to rescue the project. They are irresistible: they are the cowboy programmers. It’s men’s time.

Ben Cartwright & Sons
Ben Cartwright & Sons

Continue reading “Programmers from the Wild West”

hello, world

Personally, by reading “hello, world”, I evoke orange and warm afternoons, with my eyes strained (and soothed) by code. Nice, and overly inefficient Pascal code. In some images, a few BASIC snippets interleave, but those are not that nice to remember…

In calm thoughts, these two words (with the comma) bring to mind plenty of images. More often that not, I hold “hello, world” in fond remembrances. For this post I’ve slightly modified the default WordPress post title, in favor of the original Kernighan‘s form: no capitalization and presence of comma. Through the years, it seems to me that this sequence lightens my worries when coping with new languages, systems, things. Somehow, the mind has understood that once “hello, world” is done, then reaching the entire system is achievable. Kind of Pavlovian Conditioning, I guess.

In K&R’s C Tutorial, this feel at ease perception it’s also intended:

The only way to learn a new programming language is by writing programs in it. The first program to write is the same for all languages: Print the words hello, world. This is the basic hurdle; to leap over it you have to be able to create the program text somewhere, compile it successfully, load it, run it, and find out where your output went.

This way, “hello, world” should be our first step for pummeling through the new beast (language).
Continue reading “hello, world”