Qsr Nrwn

Website


C Programming Language

Hi you all! Still surfing or just browsing? Well�, by now you will know how does my eternal romance with C begins. I started programming on a 80286 clone without hard disk drive, and two floppy drives. I remember how bothering was to try to read a floppy while your prompt asked: 'Bad command or file name.' or so, so you have to insert again the OS floppy and try to execute the command issued moments earlier.

Well in this enviroment, on late Elementary school I took a class about programming, where the teacher just started to write the source code into the blackboard, and urged us to copy it. I only remember the screaming of the piece of chalk while she wrote down all the programme. If my memory is not so bad, programme was about the cannonical 'Hello, World!'

Time passed, and after four or five sessions typing all code from blackboard, I started to lose attention about the things about programming. Some time latter we started with concepts about batch programming, filters and redirection. I started to create some interesting (and long batch scripts). For some time that was the only kind of programming I used to do.

While being in the first year of Secondary school (which for English readers is equivalent to seventh grade), I win a bet (was about to learn all elementary algebra in a three month period) to my father and asked him to buy me a 'programmable' calculator. Was a Casio fx-6300G scientific graphics, which time to time I still see in some market places. I started to create 'programmes' for my Math homeworks (I used to be lazy about repetitive chores), so I managed to create a program to solve the general quadratic equations via general formula.

Programmes began to grow bigger and the 400-step (bytes?) boundary was a hassle. Even with this limitations I wrote a programme about Virgènere encryption algorithm (I preserve a copy of the original source code). On an avanced class I took again Programming subjects with a different view. So I started to write programmes during the high school and sophomore in GW-Basic compiler � what a mess! �, in my brain damage stage. For melancholic reasons I keep a copy of it in my HDD. Eventually in my first year on Medicine, browsing about compilers I found the TC 2.01 on Borland Community Museum, and snooping in a used bookstore I found and bought the Turbo C Bible which luckily corresponded to the Turbo C version I previously downloaded. I started to copy from the pages the different source code examples, and for the last six (soon to be seven) years I use to program in this compiler.

For some reason I will recommend to you to read next definitions taken from The Hackers' Dictionary e-text.

Classic C:
/klas'ik C/ [a play on 'Coke Classic'] n. The C programming language as defined in the first edition of K&R, with some small additions. It is also known as 'K&R C'. The name came into use while C was being standardized by the ANSI X3J11 committee. Also 'C Classic'. This is sometimes applied elsewhere: thus, 'X Classic', where X = Star Trek (referring to the original TV series) or X = PC (referring to IBM's ISA-bus machines as opposed to the PS/2 series). This construction is especially used of product series in which the newer versions are considered serious losers relative to the older ones.
indent style:
[C programmers] n. The rules one uses to indent code in a readable fashion; a subject of holy wars. There are four major C indent styles, described below; all have the aim of making it easier for the reader to visually track the scope of control constructs. The significant variable is the placement of '{' and '}' with respect to the statement(s) they enclose and the guard or controlling statement ('if', 'else', 'for', 'while', or 'do') on the block, if any.
K&R style
Named after Kernighan & Ritchie, because the examples in K&R are formatted this way. Also called 'kernel style' because the UNIX kernel is written in it, and the 'One True Brace Style' (abbrev. 1TBS) by its partisans. The basic indent shown here is eight spaces (or one tab) per level; four are occasionally seen, but are much less common.
     if (cond) {
             <body>
     }
Allman style
Named for Eric Allman, a Berkeley hacker who wrote a lot of the BSD utilities in it (it is sometimes called 'BSD style'). Resembles normal indent style in Pascal and Algol. Basic indent per level shown here is eight spaces, but four is just as common (esp. in C++ code).
     if (cond)
     {
             <body>
     }
Whitesmiths style
Popularized by the examples that came with Whitesmiths C, an early commercial C compiler. Basic indent per level shown here is eight spaces, but four is occasionally seen.
     if (cond)
             {
             <body>
             }
GNU style
Used throughout GNU EMACS and the Free Software Foundation code, and just about nowhere else. Indents are always four spaces per level, with '{' and '}' halfway between the outer and inner indent levels.
     if (cond)
       {
         <body>
       }

Surveys have shown the Allman and Whitesmiths styles to be the most common, with about equal mind shares. K&R/1TBS used to be nearly universal, but is now much less common (the opening brace tends to get lost against the right paren of the guard part in an 'if' or 'while', which is a Bad Thing). Defenders of 1TBS argue that any putative gain in readability is less important than their style's relative economy with vertical space, which enables one to see more code on one's screen at once. Doubtless these issues will continue to be the subject of holy wars.
C
n. 1. The third letter of the English alphabet. 2. ASCII 1000011. 3. The name of a programming language designed by Dennis Ritchie during the early 1970s and immediately used to reimplement UNIX; so called because many features derived from an earlier compiler named 'B' in commemoration of its parent, BCPL. Before Bjarne Stroustrup settled the question by designing C++, there was a humorous debate over whether C's successor should be named 'D' or 'P'. C became immensely popular outside Bell Labs after about 1980 and is now the dominant language in systems and microcomputer applications programming. See also languages of choice, indent style.
C is often described, with a mixture of fondness and disdain varying according to the speaker, as "a language that combines all the elegance and power of assembly language with all the readability and maintainability of assembly language".
languages of choice
n. C and LISP. Nearly every hacker knows one of these, and most good ones are fluent in both. Smalltalk and Prolog are also popular in small but influential communities.
There is also a rapidly dwindling category of older hackers with FORTRAN, or even assembler, as their language of choice. They often prefer to be known as real programmers, and other hackers consider them a bit odd (see "The Story of Mel, a Real Programmer" in appendix A). Assembler is generally no longer considered interesting or appropriate for anything but HLL implementation, glue, and a few time-critical and hardware-specific uses in systems programs. FORTRAN occupies a shrinking niche in scientific programming.
Most hackers tend to frown on languages like Pascal and Ada, which don't give them the near-total freedom considered necessary for hacking (see bondage-and-discipline language), and to regard everything that's even remotely connected with COBOL or other traditional card walloper languages as a total and unmitigated loss.

Well all my source code will be in the Allman style, because it's more organised than the other three. I use to format all source code with a powerful tool call NiceC hopefully available for download from my website. Just take your time to read documentation and format source code at your wish. I just have read the readme.txt file and found is free software and as recommended I do not intend to wrote that piece of software, so if you want to read the readme file just follow this link (I properly formatted it to fit in an HTML document)

For all functions, I will use the scheme proposed in Nabajyoti Barkakati's book "The Waite's Group, Turbo C Bible" (ISBN 0-672-22631-6), on its page xiii, with two minor modifications: I won't use the Compatibility bullet. Instead of it, it will use a "Full-ANSI compliant", "Semi ANSI-compliant", " Non-ANSI Compliant". For the footer of each section, if it is a borrowed source code or it is a contribution the proper credits will be placed (if possible) on it to the corresponding people or organisations. So let start with a primer of this scheme.

Name of function
Compliant A bullet appears if function is Full-ANSI compliant, Semi-ANSI Compliant or Non-ANSI Compliant.
PurposeShort description of where function is used.
SyntaxFull ANSI prototype. Show declaration arguments also.
Example CallShows how function is used.
IncludesLists included files needed by the function with an explanation of why each is needed.
DescriptionHow the function works and how you should use it.
Common UsesSituations in which the function is helpful.
ReturnsThe value returned by the function, if any.
CommentsSpecial notes that might help you avoid mistakes, and use the function effectively.
See alsoRelated function and how are they related.
ExamplesOne or mor complete example programmes illustrating how function is used.
AuthorAuthors name, surname(s), nick (if he or she uses it) and if available, a link to his or her website.

Oh, I almost forget to say two things: First, I have been forced to use M$-DOS in all its bitter flavours, ranging from DOS 1.0 to Win?-XP Pro Edition. I, during the forecoming years, will use if I could the Linux OS. Second, all my functions, for some reason, will be about cryptography, and will be placed outside US.


[Home]|[Start]|[C Source Code Index] 1