Wednesday, August 11, 2010

What your C\C++ teachers didnt teach you...or forgot!!!

Well their is no end to C\C++ and their never will be, simply because C++ can evolve to suit whats being demanded... Even this infinite syllabus has certain features that all of you should know. You might know most of this stuff but mind you many do not have that privilege.

Level - C++ is NOT a "High Level Language", or atleast not a conventional HLL because of its heavy use of low level features...

Header Files - YES!! you can make your own, it should only have class and function declarations and definitions in a related "library" file...but you can avoid that if you want and have entire classes as headers. They can be included just as normal header files are included in programs.

Graphics - C++ has a very primitive DOS based working environment but does support very simple graphics. More advanced graphics can also be supported by designing the right API for your own graphics driver. You can use graphics to make anything from games to animations...although that might get really frustrating and tiring!!!

Friend Class - A class can declare other classes/functions as friends to allow access to non-public class members unaccessible to outside code. Of course this was taught, but what was not told is that 'friend' is a USELESS concept. It can be used to split data between multiple classes, something that can be avoided.

IDEs - NO, the world doesnt end after Turbo C, in fact TC is very much dead nowadays. GUI based Integrated Development Environments are openly available for download that do not need (crappy) DOS to run and are much useful when it comes to more modern Operating Systems like Windows 7. But yes there is a catch, you need to download and install compilers all by yourself.

Templates - An advanced concept, templates are used on both  functions and classes. All they do is to extend the functionality of a class that has not been defined yet. Now this template function/class can use the undefined class as a regular datatype!! Templates look somewhat like this...
template ...other datatype
function/class declaration;
There can be multiple templates for the same class.

Keyword "volatile" - A type qualifier that indicates that the value of the variable will change value depending on external conditions, like hardware, operating system, network, etc. Then the compiler will always work on the current value every time a volatile variable is used.

Keyword "mutable" - A 'mutable' data member can be assigned values by a 'const' method.

New style casts - Forget c-style casts that you were taught and move on to the following for lesser bugs...
  • static_cast, 
  • dynamic_cast, 
  • reinterpret_cast and 
  • const_cast)

Threading - Several libraries that allow threading are now open source....


Exception Handling - Same as Java....

Garbage Collection - As I mentioned in my previous post, Garbage collection is simply automatic memory management incorporated into runtime. C++ was much criticized for its lack of a Garbage Collector. But automatic memory management is possible through external libraries and Smart Pointers. Also, a Garbage colletor by Boehm-Demers-Weiser can be used. It replaces malloc in C and new in C++

Interrupts - Interrupts, like the name suggests, disrupt the linear flow of control to execute certain subroutines. After that the program execution resumes from where it was suspended. Interrupts are messages to the CPU to suspend the program, execute a small executable and resume its activity. These executables are sets of instructions that are already stored in the CPU. Interrupts can be used to anything a library function can do and much beyond. Consult your IVT(Interrupt Vector Table) for details.

Register Variables - Variables can be stored directly onto CPU's registers, (which is storage available on the CPU). This feature reduced cost of accessing RAM. In embedded systems, storage is done directly onto the processor's registers as primary storage.

Hardware Application - Embedded C and C++ are dialects for embedded systems. They work directly on a processor's registers and interrupts using the familiar syntax. The focus here is on using low-level features to work closely with memory. A common example is the language used with Keil.

Updates - C++ has constantly evolved over the years thanks to a C++ Standard that is maintained as well as updated. The first was ANSI-C++ and the current is C90, also the next modern dialect of C++ will be called C++0x

2 comments:

  1. wow.. nice post!!! there were actually some i also didn't knew... keep it up..

    ReplyDelete
  2. nice ;)

    but 'current' standard is C11
    launched in dec 2011

    and ide's like DEVC++ dont require to download a compiler explicitly.nt sure abt code::blocks coz when I started using it..I already had gcc at my system :D

    ReplyDelete