C

THE LANGUAGE THAT STARTED IT ALL


Sort by: newest to oldest or oldest to newest


Wednesday, January 11, 2017 10:25:09 PM
  • Preprocessing (statements are replaced by predefined code), compiling (.c converted to .obj which is object / machine readable code) and then linking (compiled code is linked with necessary functions etc and produces a final executable).
  • cc is the built in Unix compiler while gcc is default on Linux and the industry standard compiler that is freely available. Every C program is made of directives, functions and statements.
  • An IDE is a software package that allows a user to edit, compile, link, execute and debug programs within the same interface.
  • val = 2323.99f; Its best to append the letter “f" to the end of a float number as it will be treated as a double when written without the “f” at the end and be flagged as a compiler warning for some compilers.
  • Comments can be single or multiline, they can appear above or on the same line (winged comment). Having boxed in comments make them stand out for readability.
  • By default %f with printf displays 6 digits after the decimal point. To have x digits after the decimal instead use %.xf as the format specifier.
  • A general principle in C -> wherever a value is needed, an expression of the same type will do.
  • The “f” in printf and scanf stands for formatted. Thus whenever these need to be used, the format of what they will be processing needs to be stated explicitly.
  • Macro definitions (#) are ideal for defining constants that are likely to be used across the program. The preprocessor replaces each macro by the value it represents. Note that each preprocessor directive must be on a separate line by itself.
  • Coding standards and conventions
    • When asking a user for input do not have a new line (\n) after the prompt as its best to have the user enter the input on the same line and let the user use the “enter” key for explicitly processing the next statement.
    • Use UPPER CASE for macro names as a convention
    • Some common naming conventions include camelCasing and under_scores for identifier / variable names.
    • Its good coding style to put a space before and after each operator while having blank lines to separate the program into logical units.
    • According to the C standard the compiler must replace each comment with a single space.
    • C does not allow nested comments
    • Studies have shown that 3-4 spaces is the ideal indentation
  • GCC (GNU Compiler Collection) can compile langauges such as Ada, C, C++, Fortran, Java and Objective-C.
  • { gcc -O -Wall -pedantic -ansi -std=c99 -o hello hello.c } is an example of using gcc with options. -Wall causes the compiler to produce a warning when possible errors are detected, -pedantic issues all warnings required by the C standard, -ansi turns of non standard c features while -std allows specifying the C standard that will be used for compilation.
  • A float value is actually stored in two parts as a fraction and an exponent. Thus 12.0 is actually stored as 1.5 for the fraction, 2 as the base and 3 as the exponent.

Monday, December 26, 2016 6:24:27 PM
  • Ken Thompson single handedly wrote UNIX in assembly language and then later rewrote this in C. Writing a C compiler was relatively easy and thats what gave the language its high flexibility.
  • C is still very much used in situations where memory and processing power are major factors. C++ includes all the features of C and builds on them.
  • C is as close to the machine as you can get. It gives access to bytes and addresses. The C library of standard functions gives C its flexibility. K&R C covers the entire language in 49 pages!
  • C allows a character to be added to a integer or float which is unlike other langauges. Many errors in C cannot be caught until the program is run. www.ioccc.org has good examples of obfuscated C.
  • As a good C programmer learn to use tools well -> Lint, GDB, bounds checkers, leak finders such as valgrind etc. Setting the compiler warning levels to maximum is also a good strategy to catch errors early.
  • A library is basically a collection of functions that help accomplish several common tasks. There are libraries for building user interfaces, graphics, communications, database management, networking etc. So be sure to check for them before building out you own.
  • Lint is available on UNIX and Sprint is its equivalent on LINUX machines. How does Lint help? Checks for suspicious type combinations, unused variables, unreachable code, non portable code etc.

Sunday, December 11, 2016 9:40:38 PM
  • C is the basis for several programming languages -> Java, C#, C++ and Perl. Yet, C quietly powers most of the worlds software and still remains as popular and relevant as it was back when it was launched.
  • C89 and C99 are the two main standards that shows that C has grown and evolved over time.
  • GCC is the GNU compiler collection, abstract data types in C are a cool new feature, Unicode / UCS character set are some international features of C
  • The spiral approach to learning -> Introduce difficult topics briefly and then revisit them later in the book with more details added each time is a very good way to teach / learn difficult topics
  • Programmers spend a lot of time reading other people’s code so make sure to develop a consistent style. Pointer arithmetic is not always faster than array subscripting.
  • Programs must be readable, maintainable, reliable, portable and be able to hide information. All the characteristics are important.
  • int main (void) {…} is the now standard main function definition in C99. Basically a return type must be specified explicitly for each function.
  • Some important and advanced C topics -> Pointers, Strings, Preprocessor, Structures, Unions and enumerations
  • The standard C library has been expanded in C99 and its wise to use functions from there when needed instead of manually coding the same functionality each time
  • C is a functional programming language as opposed to OOP based languages. C was invented for computer programmers.

Tuesday, October 4, 2016 8:55:46 PM
  • C has no abstract types like Strings and Lists, no garbage collection and memory must be managed in the heap by the programmer and hence its common to see errors like buffer overrun vulnerability.
  • C++ is essentially a superset of C that supports type extension, object oriented programming, and programming with generics. While C++ is extremely popular the foundation does come from C.
  • Java adopted heavily from C++ and hence from C. Java is much more verbose with garbage collection and object oriented in its basic design.
  • There are no classes in C—all executable code is held in functions and C source code is held in .C extension files.
  • A core file is essentially a snapshot of the address space of the process generated commonly during c program failures / core dumps.
  • GNU C Compiler (gcc) is a very popular C compiler along with others like Clang. a.out is the default executable produced when a .c file is compiled with gcc.

Tuesday, October 4, 2016 8:41:05 PM
  • "C is a general-purpose programming language which features economy of expression, modern control flow, and a rich set of operators.” say Kernighan & Ritchie.
  • Bell Labs helped create Unix then B which eventually lead to the creation of C. C89, C99 & C11 are how the standards evolved over time.
  • Its commonplace to hear that C is extremely fast and is hence used in systems software i.e to write software that helps other software systems run like operating systems, graphics libraries, editors, compilers, interpreters, virtual machines, embedded software and several utilities.
  • So its not surprising that a lot of the software systems that we have and use around us are fundamentally based on C. Its been 44 years since C was first introduced and has stood the test of time. C has and will continue to be incredibly relevant. It helps to know C!
  • What you write is what you get, close to the machine, efficient use of memory, very few constraints and highly portable are some key aspects of the C language.




Made with by Praharsh Srinivasula