Science Fair Projects Ideas - Directive (programming)

All Science Fair Projects

      

Science Fair Project Encyclopedia for Schools!

  Search    Browse    Forum  Coach    Links    Editor    Help    Tell-a-Friend    Encyclopedia    Dictionary     

Science Fair Project Encyclopedia

For information on any area of science that interests you,
enter a keyword (eg. scientific method, molecule, cloud, carbohydrate etc.).
Or else, you can start by choosing any of the categories below.

Directive (programming)

A directive is an instruction to a programming language compiler about how to compile a program. Rather than providing code per se, a programmer uses a directive to modify how or even if code is compiled.

Overview

Directives are used in several relatively low-level languages such as assembly programming, C and C++. In assembly language, directives generally tell the assembler the target platform, delineate segments, and so on. In C++, directives are used for conditional compiling, macros and including other files.

Examples

C/C++

There are several preprocessor directives in C and C++. The following are a few examples, but do not illustrate every directive or every situation in which one might find them. Note the lack of semicolons at the end of the lines: directives are instructions to the preprocessor, not the compiler, and they follow their own language grammar and rules.

#include <iostream>

This is the most common form for most programmers. It instructs the preprocessor to read a file from disk and insert its contents into the source code file. In this case it reads the general I/O streams header from the compiler's standard header directory.

#define PI (3.14159)
cout << (2.0 * PI) << endl;

Macros are, essentially, preprocessor variables that are expanded inline into the source code. This example defines a macro named PI that is expanded to 3.14159 everywhere it is found in the code. This is deprecated in most cases, as C and C++ both provide constants that are more efficient and provide strong typing.

#if defined LINUX
// Do some Linux stuff here
#elif defined WINDOWS
// Do some Windows stuff here
#endif

Another common directive, this generally is used for conditional compilation. This example shows a directive that chooses two sets of code to include in the preprocessor output depending on which operating system macro is defined.

Last updated: 05-07-2005 13:27:25
10-26-2009 08:16:03
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details
Science kits, science lessons, science toys, maths toys, hobby kits, science games and books - these are some of many products that can help give your kid an edge in their science fair projects, and develop a tremendous interest in the study of science. When shopping for a science kit or other supplies, make sure that you carefully review the features and quality of the products. Compare prices by going to several online stores. Read product reviews online or refer to magazines.

Start by looking for your science kit review or science toy review. Compare prices but remember, Price $ is not everything. Quality does matter.
Science Fair Coach
What do science fair judges look out for?
ScienceHound
Science Fair Projects for students of all ages
All Science Fair Projects.com Site
All Science Fair Projects Homepage
Search | Browse | Links | From-our-Editor | Books | Help | Contact | Privacy | Disclaimer | Copyright Notice