Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Directive (programming)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Other languages== * In [[Ada (programming language)|Ada]], compiler directives are called '''pragmas''' (short for "pragmatic information"). * In [[Common Lisp]], directives are called '''declarations''', and are specified using the <code>declare</code> construct (also <code>proclaim</code> or <code>declaim</code>).{{sfn|Steele|1990|loc=[https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node103.html Chapter 9: Declarations], p. 215–237}} With one exception, declarations are optional, and do not affect the semantics of the program. The one exception is <code>special</code>, which must be specified where appropriate. * In [[Turbo Pascal]], directives are called '''significant comments''', because in the language [[grammar]] they follow the same syntax as [[comment (computer programming)|comment]]s. In Turbo Pascal, a significant comment is a comment whose first character is a [[dollar sign]] and whose second character is a letter; for example, the equivalent of C's <code>#include "file"</code> directive is the significant comment <code>{$I "file"}</code>. * In [[Perl]], the [[keyword (computer programming)|keyword]] "<code>[http://perldoc.perl.org/functions/use.html use]</code>", which imports modules, can also be used to specify directives, such as <code>use strict;</code> or <code>use utf8;</code>. * [[Haskell (programming language)|Haskell]] pragmas are specified using a specialized comment syntax, e.g. <code>{-# INLINE foo #-}</code>.<ref>{{cite web|title=7.20. Pragmas|url=http://www.haskell.org/ghc/docs/7.8.3/html/users_guide/pragmas.html|website=GHC 7.8.3 Documentation|access-date=18 July 2014}}</ref> It is also possible to use the C preprocessor in Haskell, by writing <syntaxhighlight lang="Haskell" inline>{-# LANGUAGE CPP #-}</syntaxhighlight>. * [[PHP]] uses the directive <code>declare(strict_types=1)</code>. * In [[PL/I]], directives begin with a [[Percent sign]] (<code>%</code>) and end with a semicolon (<code>;</code>), e.g., <code>%INCLUDE ''foo'';</code>, <code>%NOPRINT;</code>, <code>%PAGE;</code>, <code>%POP;</code>, <code>%SKIP;</code>, the same as with preprocessor statements. * [[Python (programming language)|Python]] has two directives – <code>from __future__ import feature</code> (defined in [https://www.python.org/dev/peps/pep-0236/ PEP 236 -- Back to the __future__]), which changes language features (and uses the existing module import syntax, as in Perl), and the <code>coding</code> directive (in a comment) to specify the encoding of a source code file (defined in [https://www.python.org/dev/peps/pep-0263/ PEP 263 -- Defining Python Source Code Encodings]). A more general directive statement was proposed and rejected in [https://www.python.org/dev/peps/pep-0244/ PEP 244 -- The `directive' statement]; these all date to 2001. * [[ECMAScript]] also adopts the <code>use</code> syntax for directives, with the difference that pragmas are declared as string literals (e.g. <code>"use strict";</code>, or <code>"use asm";</code>), rather than a function call. *In [[Visual Basic]], the keyword "<code>Option</code>" is used for directives: ** <code>Option Explicit On|Off</code> - When on disallows implicit declaration of variables at first use requiring explicit declaration beforehand. ** <code>Option Compare Binary</code> - Results in string comparisons based on a sort order derived from the internal binary representations of the characters - e.g. for the English/European code page (ANSI 1252) A < B < E < Z < a < b < e < z < À < Ê < Ø < à < ê < ø. Affects intrinsic operators (e.g. =, <>, <, >), the Select Case block, and VB runtime library string functions (e.g. InStr). ** <code>Option Compare Text</code> - Results in string comparisons based on a case-insensitive text sort order determined by your system's locale - e.g. for the English/European code page (ANSI 1252) (A=a) < (À = à) < (B=b) < (E=e) < (Ê = ê) < (Z=z) < (Ø = ø). Affects intrinsic operators (e.g. =, <>, <, >), the Select Case block, and VB runtime library string functions (e.g. InStr). ** <code>Option Strict On|Off</code> - When on disallows: *** typeless programming - where declarations which lack an explicit type are implicitly typed as Object. *** late-binding (i.e. dynamic dispatch to CLR, DLR, and COM objects) on values statically typed as Object. *** implicit narrowing conversions - requiring all conversions to narrower types (e.g. from Long to Integer, Object to String, Control to TextBox) be explicit in code using conversion operators (e.g. CInt, DirectCast, CType). ** <code>Option Infer On|Off</code> - When on enables the compiler to infer the type of local variables from their initializers. * In [[Ruby (programming language)|Ruby]], interpreter directives are referred to as '''pragmas''' and are specified by top-of-file comments that follow a <code>key: value</code> notation. For example, <code>coding: UTF-8</code> indicates that the file is encoded via the [[UTF-8]] [[character encoding]]. * In [[C Sharp (programming language)|C#]], compiler directives are called pre-processing directives. C# does not technically handle these using a preprocessor, but rather directly in the code. There are a number of different compiler directives, which mostly align with those from C and C++, including <code>#pragma</code>, which is specifically used to control compiler warnings and debugger checksums.<ref>{{Cite web|url=https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/lexical-structure|title=Lexical structure - C# language specification|last=dotnet-bot|website=docs.microsoft.com|language=en-us|access-date=2019-11-01}}</ref><ref>{{Cite web|url=https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-pragma|title=#pragma - C# Reference|last=BillWagner|website=docs.microsoft.com|language=en-us|access-date=2019-11-01}}</ref> C# also features some directives not used in C or C++, including <code>#nullable</code> and <code>#region</code>. C# also does not allow function-like macros, but does allow regular macros, for purposes such as conditional compilation. * The [[SQLite]] [[DBMS]] includes a PRAGMA directive that is used to introduce commands that are not compatible with other DBMS.<ref>{{cite web |title=Pragma statements supported by SQLite |url=https://www.sqlite.org/pragma.html |website=www.sqlite.org}}</ref> * In [[Solidity]], compiler directives are called pragmas, and are specified using the `pragma` keyword.<ref>{{Cite web |title=Layout of a Solidity Source File — Solidity 0.8.27 documentation |url=https://docs.soliditylang.org/en/latest/layout-of-source-files.html#pragmas |access-date=2024-06-03 |website=docs.soliditylang.org}}</ref> ===Assembly language=== * In [[assembly language]], directives, also referred to as pseudo-operations or "pseudo-ops", generally specify such information as the target machine, mark separations between code sections, define and change assembly-time variables, define macros, designate conditional and repeated code, define reserved memory areas, and so on. Some, but not all, assemblers use a specific syntax to differentiate pseudo-ops from instruction mnemonics, such as prefacing the pseudo-op with a period, such as the pseudo-op <code>.END</code>, which might direct the assembler to stop assembling code. <!-- Should there be examples? --> ===PL/SQL=== * [[Oracle Corporation]]'s [[PL/SQL]] procedural language includes a set of compiler directives, known as "pragmas".<ref> {{cite book | last1 = Feuerstein | first1 = Steven | author-link1 = Steven Feuerstein | last2 = Pribyl | first2 = Bill | title = Oracle PL/SQL Programming | date = 23 January 2014 | url = https://books.google.com/books?id=vQaoAgAAQBAJ | edition = 6 | publisher = O'Reilly Media, Inc. | publication-date = 2014 | isbn = 9781449324414 | access-date = 2016-06-16 | quote = PL/SQL has a PRAGMA keyword with the following syntax: PRAGMA ''instruction_to_compiler''; [...] PL/SQL offers several pragmas [...] }} </ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)