So I know what pragma is, and what it's used for, but what is the meaning of the word itself? I've used it many times in code, but I never really knew what the word actually means or stands for.
相关问题
- Sorting 3 numbers without branching [closed]
- Multiple sockets for clients to connect to
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
From the ancient Greek:
As with all things geeky, somebody was trying to be way too clever for their own good. Unfortunately its original meaning becomes lost to the rest of us (unless you have Google and a Latin/Greek to English dictionary handy).
http://www.studylight.org/lex/grk/view.cgi?number=4229
http://www.bibletools.org/index.cfm/fuseaction/Lexicon.show/ID/G4229/pragma.htm
Original (that is what the above page says, but I don't have a copy of that book):
According to a US Government-owned(!) document describing the design of Ada: Rationale for the Design of the Ada® Programming Language :
I like the (last caveat) there...
This cross references well with on-line greek dictionaries (e.g. as quoted by Martin York) that say pragma (πράγμα, as commented on the original question by asveikau) means:
Seems the key to understanding is the word action rather than information.
In mathematics and logic, a pragma is a given, a fact, a prerequisite to the argument, problem, or proof which follows.
Pulled right from Wikipedia(programming):
While it's not explicitly for C, this should answer your question anyway. However, as T.J. pointed out, there is no valid source given for this piece of information.
The programming language Ada was quite possibly the first compiler to use pragma to specify preprocessor directives. The word was used as a shortened form of "pragmatic information"
When the C programming language was designed it didn't initially have pragma directives, but was quickly added to the specification to support custom compiler features. (ie. #pragma optimization_level for the intel C++ compiler)
Since then many languages have implemented pragma in some form or another, including C#, but they are often limited to build time warnings and optimization hints.
One of the most common and useful pragmas, in non-standard C and C++, is #pragma once used to specify that a file should only be included once.