Chapter 1
Introduction to the X2c Xbase compiler
The X2c Xbase compiler frees your applications programs from the constraints of the Xbase language by converting them into the powerful and portable C language. X2c works with Clipper, Foxbase, FoxBASE, Genifer, WordTech, dBman and other Xbase companion software to improve the efficiency, speed, and portability of your Xbase applications programs.
Who Needs X2c?
Xbase products provide a complete answer for many database management needs. However, there comes a point in development when other Xbase products can provide only a partial solution. Compiling Xbase code into C with X2c expands the value of Xbase code for:
o Xbase programmers who need to move Xbase applications to different computers.
o Xbase programmers who need to integrate an Xbase application with an application written in C.
o Xbase programmers who have pushed other Xbase languages to the limit.
o Power users who want fast-running programs.
o Xbase specialists who need to convert their applications programs to C -- but don't have time to learn a new language.
WHY C ?
With all of the programming languages available on the PC, C is the language of choice, because:
C is available on UNIX, XENIX, OS/2, MS-DOS networks,
most mini-computers and mainframe computers.
C can be used invisibly as a target language.
C programs are structured more efficiently and
flexibly than Xbase programs.
C programs run faster.
C is a compiled language. Its executable programs
cannot be modified by users.
Is the created C code efficient, compared to hand written C code ?
The created code is almost as efficient as C code that is written from scratch, because X2c produces C code that by its very structure improves the program so much that hand improvements tend to be minor. Since the X2c process takes far less time than you would need to rewrite your applications in C and most programs only have bottlenecks in a few places, you can concentrate on the program sections that really need hand work.
How is X2c being used ?
X2c is used by large and small corporations to convert existing Xbase code into C source code. In some cases, the C programs are moved to a computer with the Unix operating system, then compiled so the applications can be run on those systems. In other cases, the Xbase programs are converted to C to improve run-time speed. Other uses include applications that require integrating Xbase database processing logic with process control or graphics in C.
Companies with experienced Xbase programmers often continue to develop and enhance applications in Xbase, then convert tested code into C. Companies who have experienced Xbase programmers that they want to learn C use X2c as both a learning and productivity tool. At the same time the Xbase programmers are reviewing comparative code samples, they are producing C source code.
The X2c for Linux is a specially prepared version that looks and acts like most other languages on Linux - the one command compiles the Xbase .prg program from source to exectatable binary, with the same options gcc or other compiler allow.
Colors of Xbase
INTERPRETED vs. COMPILED LANGUAGES:
Xbase, at heart, is an interpreted language. When you write a program, as a text file, you run your application directly from that text file. The Xbase .prg files can be read and edited easily.
C is a compiled language. After you write a program in C, you must use a compiler and linker to create an executable (runnable) program. The .c and .h text files which contain your original C code can be read and edited easily. The object (.obj) files are created by the compiler. The executable (.exe) files are programs created by the linker.
Object and executable files cannot be read and edited because they are machine-internal format binary files. In addition, sets of standard functions, in object file format, can be combined into library files, so that only the needed ones are loaded into a program.
There is another key difference between an interpreter and a compiler - the world view. Xbase provides a whole world to work within, often called 'the dot prompt'. For example, interactive statements like CREATE and BROWSE allow directly creating databases and working with them. The compiled environment does not have these amenities and, more important to the Xbase user, the compiler does not tell you much of the information the interpreter tells you, unless you ask ahead of time.
Dialects of Xbase:
Since the Xbase language was developed and became popular as dBASE II from Ashton-tate in 1981, a number of alternatives have been developed. These include Clipper (from Nantucket), Foxbase (from Fox software) and QuickSilver (from Wordtech). There are others but dBASE III plus (from Ashton-tate) and these three comprise the bulk of the Xbase language user community. Each of these have their own special features and benefits. Because X2c is focused on the advanced user, X2c handles many of the extensions beyond the basic dBASE III language.
For the dBASE user:
For someone used to using dBASE III plus, from Ashton-tate, there are two learning phases: learning to use a compiled environment and learning the new features available from X2c. In particular, in the compiled environment there is no cozy world with CREATE and BROWSE and EDIT.
For the Fox user:
Foxbase plus is the closest to dBASE III plus in its operation yet has many language extensions. In addition, Fox has made such performance improvements over dBASE III that the speed improvements due to C are not as clear cut as before. The new user of X2c has to have a clear focus of what is expected, such as portability. X2c has all of and dBx most of the language extensions of Foxbase+ 2.1.
For the Clipper user:
Clipper is a compiler and so if you are a Clipper user, you are already familiar with compiled code and its advantages. Since Clipper has many of the language characteristics of C, moving to X2c is easiest for the Clipper user. In addition, X2c has all the Xbase language extensions of Clipper (Summer 87).
X2c as a dialect of Xbase:
There are three components to any language, in language design terms: syntax, semantics and implementation. These are the 'look', the 'meaning' and the 'how its done 'of the language.
By using proper programming rules at the Xbase language level, your programs can work both with other Xbase dialects and X2c.
X2c includes the C functions to provides all operational characteristic of Xbase.
Where worlds collide:
The Macro operator (&):
A key difference between an interpreter and compiler shows up in an essential part of the Xbase language: the Macro. The macro, as supported in the Xbase interpreter, relies on having the whole language available at the time the program is running. This is what allows variables, expressions and even keywords, to be placed in a macro and understood at run-time. A compiler has a very different run-time environment than an interpreter and so much of this information and code is not available.
The essence of the confusion around macros stems from the perception that all macros are the same. Because the language allows the (&) character any place, the visual effect masks the reason the macro is being used.
In Xbase, there are at least five (5) totally different types of macro uses, and as explained later, many of these act no different in Xbase than in C.
Only a few require special handling or are limited.
Variable handling:
One key limit to Xbase's performance and difference with C is how it handles its variables. These ranges from what code knows about a variable (called its scope) to how it is stored internally. X2c masks many of these differences automatically. In particular, C requires all variables to be declared - X2c does this for you.
How to use this manual
The documentation for X2c for Linux is divided into three sections:
0. Installation procedures and release notes.
I. User's manual (you are reading)
II. Language Reference (X2cman on disk)
III. Programming reference documents (On disk)
Start at the beginning
If you haven't already done so, install your X2c as described in the Installation Manual and review
To verify that your system is installed correctly, run the HELLO tutorial as described in Chapter 2.
Once you have verified that your system is installed correctly, run the rest of the tutorials, and continue to study the rest of the documentation.
To determine the exact Xbase language supported by X2c, run the program x2cman that will be installed with X2c.