| iMatix home page
| Libero home page | Libero documentation
| << | < | > | >>
Libero Libero
Version 2.32

 

The C Language

Overview

What Is C?
C is part of UNIX originally, now almost a universal language. It is a very general purpose language, and typically used for systems programming. ANSI C is a widely supported standard.
Portability
ANSI C compilers are available on (almost) all platforms. ANSI C programs can be highly portable if you eschew compiler extensions, and don't rely on libraries that are not portable. Some UNIX vendors include non-ANSI compilers but charge extra for ANSI C compilers. Luckily the GNU gcc compiler is excellent and ported to most UNIX systems.
Pros and Cons
Pros: C is flexible and widely known; it is a small and clean language. C compilers are generally well-tuned and sometimes exceptionally good. Cons: no easy string handling; sloppy programmers write horrendous C code.
How To Get It
How to get it On UNIX boxes, 'cc', or 'gcc'. GNU gcc is widely available and well-regarded. Commercial C compilers are available for almost all platforms from mainframes to embedded systems.
Libero Supports
ANSI C, though you can freely use any extensions you need to. Libero generates ANSI C code, so your compiler must be happy with things like prototypes.

Working With C

Example of code

Code fragments:

/****************   MODULE FUNCTION NAME   *****************/

MODULE module_function_name (void)
{
                             /* Empty module needs no code */
}

static type private_function_name (argument,...) {
    the_next_event = ok_event;
    raise_exception (error_event);
}

A fuller example.

Notes

I've used Libero to help me write C programs for a few years. It would be false to say I used Libero all the time; this is simply not the case. For example, I wrote Libero in C: there are 12 separate source files, and four of these have dialogs. I used a dialog whenever I had a single function that got rather complex. In Libero, this happens to be in:

  1. the module that parses and loads a dialog (lrload);
  2. the code generator module, which scans the schema and interprets the simple language embedded in the schema (lrcode);
  3. the two modules that evaluate expressions (lrcalc and lreval).

It's probably no coincidence that all these modules do some kind of parsing. Libero is a code generator, so it's normal that the most complex modules are parsers. As a consultant, I've written some profoundly complex C programs using Libero. In at least one case I still don't see any other way that I could have done the project.

When you write a C program using Libero, you tend to use a lot of source-local variables. This is disturbing to some programmers, who reckon that a program must consist of lots of internested modules that hide data from each other. Sure, this is one way of managing complexity. Still, modules in a Liberated program aren't nested; they all sit at the same level below the dialog. They all share (mostly) a common set of data objects. In real programs this seems to work nicely, so if you have problems with it, just close your eyes the first few times.


| << | < | > | >>
| Libero's Languages | The Awk Language | The C Language | The C++ Language | The COBOL Language | The GNU Borne-Again Shell Language | The Java Language | The Microsoft Setup Basic Language | The MS Visual Basic Language | The Perl Language | The Rexx Language | The UNIX C Shell Language | The UNIX Bourne Shell Language | The UNIX Korn Shell Language | The 80x86 Assembler Language
iMatix
Copyright © 1996-97 iMatix