Directive (programming)
Encyclopedia
In computer programming
Computer programming
Computer programming is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages. The purpose of programming is to create a program that performs specific operations or exhibits a...

, the term directive is applied in a variety of ways that are similar to the term command. It is also used to describe some programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

 constructs (e.g. those specifying how a compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

 or assembler
Assembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...

 should process its input).

To distinguish a directive from a command or statement, a directive may involve a pre or post processing command or macro. Its second use involves a statement that affects local or more global options or that applies to a block of programming code but by itself does not perform any action.

This term could be used to refer to proprietary third party tags and commands (or markup) embedded in code or comments that result in additional executable processing that extend the existent compiler, assembler and language constructs present in the development environment.

Assembly language

In assembly language
Assembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...

, directives generally specify such information as the target platform, mark the separations between sections, and so on. For instance, the commonly seen directive "ALIGN", which inserts in the current section as many byte
Byte
The byte is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, a byte was the number of bits used to encode a single character of text in a computer and for this reason it is the basic addressable element in many computer...

s as needed to preserve word-alignment, is generally referred to as a "directive", despite the fact that it does correspond to a particular construct in the generated code.

The C preprocessor

In C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 and C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

, the language supports a simple macro preprocessor. Source lines that should be handled by the preprocessor, such as #define and #include are referred to as preprocessor directives.

Another C construct, the #pragma directive, is used to instruct the compiler to use pragmatic or implementation-dependent features. Two most notable users of this directive are OpenMP
OpenMP
OpenMP is an API that supports multi-platform shared memory multiprocessing programming in C, C++, and Fortran, on most processor architectures and operating systems, including Linux, Unix, AIX, Solaris, Mac OS X, and Microsoft Windows platforms...

 and OpenHMPP

Syntactic constructs similar to C's preprocessor directives, such as C#'s #if, are also typically called "directives", although in these cases there may not be any real preprocessing phase involved.

In other high-level languages

In Ada
Ada (programming language)
Ada is a structured, statically typed, imperative, wide-spectrum, and object-oriented high-level computer programming language, extended from Pascal and other languages...

, compiler directives are called pragmas (short for "pragmatic information").

In Turbo Pascal
Turbo Pascal
Turbo Pascal is a software development system that includes a compiler and an integrated development environment for the Pascal programming language running on CP/M, CP/M-86, and DOS, developed by Borland under Philippe Kahn's leadership...

, directives are called significant comments, because in the language grammar
Grammar
In linguistics, grammar is the set of structural rules that govern the composition of clauses, phrases, and words in any given natural language. The term refers also to the study of such rules, and this field includes morphology, syntax, and phonology, often complemented by phonetics, semantics,...

 they follow the same syntax as comment
Comment (computer programming)
In computer programming, a comment is a programming language construct used to embed programmer-readable annotations in the source code of a computer program. Those annotations are potentially significant to programmers but typically ignorable to compilers and interpreters. Comments are usually...

s. In Turbo Pascal, a significant comment is a comment whose first character is a dollar sign
Dollar sign
The dollar or peso sign is a symbol primarily used to indicate the various peso and dollar units of currency around the world.- Origin :...

 and whose second character is a letter; for example, the equivalent of C's #include "file" directive is the significant comment {$I "file"}.

In Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

, the keyword
Keyword (computer programming)
In computer programming, a keyword is a word or identifier that has a particular meaning to the programming language. The meaning of keywords — and, indeed, the meaning of the notion of keyword — differs widely from language to language....

 "use" can introduce a "pragma", such as use strict; or use utf8;. ECMAScript
ECMAScript
ECMAScript is the scripting language standardized by Ecma International in the ECMA-262 specification and ISO/IEC 16262. The language is widely used for client-side scripting on the web, in the form of several well-known dialects such as JavaScript, JScript, and ActionScript.- History :JavaScript...

 also uses this keyword to introduce "pragmas".

In Visual Basic
Visual Basic
Visual Basic is the third-generation event-driven programming language and integrated development environment from Microsoft for its COM programming model...

, the statement "Option Explicit On" instructs the VB compiler to require all variable declarations before use. There are also a few other variations to the Option keyword, such as:
  • Option Strict On - Requires that implicit type casts are only to wider types.
  • Option Compare Binary - Tells the compiler to compare text using a binary algorithm.
  • Option Compare Text - Tells the compiler to compare text using a textual algorithm.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK