Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 The C preprocessor  





2 History  





3 Other languages  



3.1  Assembly language  





3.2  PL/SQL  







4 See also  





5 Footnotes  





6 References  





7 External links  














Directive (programming)






Čeština
Deutsch
Español
Esperanto
Italiano

Polski
Português
Русский
Українська


 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


Incomputer programming, a directiveorpragma (from "pragmatic") is a language construct that specifies how a compiler (or other translator) should process its input. Depending on the programming language, directives may or may not be part of the grammar of the language and may vary from compiler to compiler. They can be processed by a preprocessor to specify compiler behavior, or function as a form of in-band parameterization.

In some cases directives specify global behavior, while in other cases they only affect a local section, such as a block of programming code. In some cases, such as some C programs, directives are optional compiler hints and may be ignored, but normally they are prescriptive and must be followed. However, a directive does not perform any action in the language itself, but rather only a change in the behavior of the compiler.

This term could be used to refer to proprietary third-party tags and commands (or markup) embedded in code that result in additional executable processing that extend the existing compiler, assembler and language constructs present in the development environment. The term "directive" is also applied in a variety of ways that are similar to the term command.

The C preprocessor[edit]

InC and C++, 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 notable users of this directive are OpenMP and OpenACC.

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.

All preprocessor commands begin with a hash symbol (#) with the exception of the import and module directives in C++.[1]

History[edit]

Directives date to JOVIAL.[2]

COBOL Had a COPY directive.

InALGOL 68, directives are known as pragmats (from "pragmatic"), and denoted pragmatorpr; in newer languages, notably C, this has been abbreviated to "pragma" (no 't').

A common use of pragmats in ALGOL 68 is in specifying a stropping regime, meaning "how keywords are indicated". Various such directives follow, specifying the POINT, UPPER, RES (reserved), or quote regimes. Note the use of stropping for the pragmat keyword itself (abbreviated pr), either in the POINT or quote regimes:

.PR POINT .PR
.PR UPPER .PR
.PR RES .PR
'pr' quote 'pr'

Today directives are best known in the C language, of early 1970s vintage, and continued through the current C99 standard, where they are either instructions to the C preprocessor, or, in the form of #pragma, directives to the compiler itself. They are also used to some degree in more modern languages; see below.

Other languages[edit]

Assembly language[edit]

PL/SQL[edit]

See also[edit]

Footnotes[edit]

  1. ^ "P1857R1 - Modules Dependency Discovery".
  • ^ "Chapter 17 - Directives" (PDF). Computer Programming Manual for JOVIAL (J73) Language (PDF) (Technical report). June 1981. pp. 243–263. RADC-TR-81-143. Retrieved May 28, 2023.
  • ^ Steele 1990, Chapter 9: Declarations, p. 215–237.
  • ^ "7.20. Pragmas". GHC 7.8.3 Documentation. Retrieved 18 July 2014.
  • ^ dotnet-bot. "Lexical structure - C# language specification". docs.microsoft.com. Retrieved 2019-11-01.
  • ^ BillWagner. "#pragma - C# Reference". docs.microsoft.com. Retrieved 2019-11-01.
  • ^ "Pragma statements supported by SQLite". www.sqlite.org.
  • ^ "Layout of a Solidity Source File — Solidity 0.8.27 documentation". docs.soliditylang.org. Retrieved 2024-06-03.
  • ^ Feuerstein, Steven; Pribyl, Bill (23 January 2014). Oracle PL/SQL Programming (6 ed.). O'Reilly Media, Inc. (published 2014). ISBN 9781449324414. Retrieved 2016-06-16. PL/SQL has a PRAGMA keyword with the following syntax: PRAGMA instruction_to_compiler; [...] PL/SQL offers several pragmas [...]
  • References[edit]

    External links[edit]


    Retrieved from "https://en.wikipedia.org/w/index.php?title=Directive_(programming)&oldid=1227058081"

    Category: 
    Computer programming
    Hidden categories: 
    Articles with short description
    Short description is different from Wikidata
    Articles needing additional references from December 2013
    All articles needing additional references
     



    This page was last edited on 3 June 2024, at 12:38 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki