|FROM ||Ruben Safir
|SUBJECT ||Subject: [NYLXS - HANGOUT] C++ Workshop _ Syntax Basics
Before exploring how we actually represent data in our C++ programs, I
to introduce a formal discussion of basic C++ syntax, which, like data
doesn't get enough attention in most standardized texts.
All programming languages require syntax rules in order for the
to parse and create working machine code. These syntax rules require
understanding of core componenets. These components include files,
statements, data and operators.
Starting from the top, first you have files, and files usually have
rules. C++ inherits from C nearly all the file structures, and actually
requires a greater knowledge in more detail and at an earlier level of
expertise. C++, because of its object oriented design depends heavely
library creation. In fact, even for beginners, most of your work
on the library level.
All C programs inherit from the Unix enviroment, which co-developed with
the need for an initiation of the main function definition. All C
start with main, and main will then absorb and use all other parts of
systems libraries and programming to produce your completed program.
is located in your upper most programming file.
Standard Programming Files: A standard programming file is when the top
most programming will take place. In the C language, most of your code,
a beginner takes place in this file. Most commonly these files have a
either .cc oro .C. file.C for example is a standard C++ File name.
A standard programming file will have several components:
1) Include Prepocessor Directives - These import header files and define
the definitions of
the symbols which your not spontaneously creating, that your program
And include directive might look like this:
Which tells the compiler to load up the defintions of all the functions
objects defined in the iostream library.
Standard C++ libraries are included using the angle blacket notions as
They are search for by your compiler in a set of standard locations
are defined by your compiler and programming enviroment (something I
mind understanding better on modern Linux and GNU enviroments).
If you use the syntax
with double quotes, the compiler will look for these headers in the
C libraries are accessable in C++ and can either have a standard C
***Note the .h suffix being included***
or use the C++ version
2) Macro and other Prepocessor Compiler Directives - Help set up
which libraries and header files are brought into your program to help
duplication and to create different versions of a program as might be
for differing archetecture or conditions.
The list of Preprocessor Directives are as follows:
#include (as discussed above)
A Macro directive might look like this:
Development of skills using these directives, which is a language in a
is one of the skills that advanced C and C++ coders have that seperate
This Macro is telling the compiler to include the libraries and symbols
for iostream and string from the core C++ library if and ONLY IF, the
HEAD, in the compiler instructions, haven't been already defined.
There are also constants that your program has which the compiler adds
to your code which include
__DATE__ and __TIME__ are the date and time the program is compiled.
3) Original Code and runtime directives starting with main.
C++ has added a new programming directive called the "using" directive
which is used to create namespace. Namespace gives a finer grain
of which symbols your code recognizes in a specified space. Its really
important and in many ways was a long time coming to the C family of
Most importantly it prevents you from accidently stepping on library
or words that you might not have been aware of or that programmers after
might not be aware of. It also allows to define the same symbol in
locations of your code without stepping on your own toes.
So todays modern C++ main program files might look something look
using namespace std;
int main( int argc, const char* argv )
//YOUR PROGRAMMIGN CODE
There is a catch to the namespace usage though. It might very well be
that your library files, especially if you are creating them yourself,
which you will in C++, have the using directive. If so, you will likely
depend on them.
Header files normally have a .h suffix. file1.h would be an exampe of a
header file for C or C++. These are the files that are being included
#include preprocessor directive.