#pragma 编译指令里单词或术语 pragma 的词义究竟是什么

yisikaipu 2012-08-28 06:17:13
先举个例子,术语 macro 宏。原意:宏大。指一大块指令。然后泛化为指令替换

那么 pragma 呢?原意:实用?

很费解,为何用这么个看起来不着边际的词

求典故

...全文
257 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
yisikaipu 2012-08-28
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 的回复:]至于它的出处,可以参考下面帖子中:
Where does the word “pragma” come from?
第一楼martin clayton的回答。[/Quote]

豁然开朗!

其实以前看过这个贴,虽然没去看过那个 US Government-owned(!) document

但错过了答案,因为思维被定势了。C++标准和MSDN强调的都是 implementation-defined,完全没有提到 pragma 本身就有 directive 的含义

C++标准
$16.6 Pragma directive
A preprocessing directive of the form
# pragma pp-tokensopt
causes the implementation to behave in an implementation-defined manner. Any pragma that is not recognized by the implementation is ignored.

MSDN
http://msdn.microsoft.com/en-us/library/d9x1s805(v=vs.100).aspx
Pragma directives specify machine- or operating-specific compiler features. ...

Each implementation of C and C++ supports some features unique to its host machine or operating system. Some programs, for example, must exercise precise control over the memory areas where data is put or to control the way certain functions receive parameters. The #pragma directives offer a way for each compiler to offer machine- and operating system-specific features while retaining overall compatibility with the C and C++ languages.

Pragmas are machine- or operating system-specific by definition, and are usually different for every compiler. Pragmas can be used in conditional statements, to provide new preprocessor functionality, or to provide implementation-defined information to the compiler.

就连这个 owned by the United States Government 的文档,也提 implementation :)
Ada
http://archive.adaic.com/standards/83rat/html/ratl-02-01.html
Some pragmas are defined by the language (see Annex B of the reference manual). It is expected that other pragmas will be defined by various implementations, in particular for the programming support environments developed around the Ada language.

但是,首先它讲的就是
...a program text can include elements that have no influence on the meaning of the program but are included as information and guidance for the human reader or for the compiler. These are:
Comments
Pragmas

A pragma (from the Greek word meaning action) is used to direct the actions of the compiler in particular ways, but has no effect on the semantics of a program (in general). ...


我现在的理解如下:

pragma 源于希腊语,有deed/action之意,这个意思可以直接对应到 directive。但英语没有pragma,只有派生的词,比如 pragmatic,其意义反而偏离了原意

如此,说 pragma 是 pragmatic information 之意的说法恐怕是搞颠倒了
martin clayton 在解答里说:Seems the key to understanding is the word action rather than information 是不是也有点这个意思 :)

答案:pragma 的原意就是 指令。写 #pragma 就相当于写 #directive

有反驳的吗
pathuang68 2012-08-28
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]

引用 10 楼 的回复:咬文嚼字:

原意 ... based on practical rather than theoretical considerations
可以对应到 implementation-dependent

所以我的理解是
#pragma 原意是 此处指令依据具体实现

不仅是原意,也是现在的意思。但我想知道的是,为什么用这么个高深的词而不用更易懂的词,……
[/Quote]

1. 俺很佩服楼主的钻研精神
2. #pragma 后面跟的是编译器指示,有点像Oracle中的hint

至于它的出处,可以参考下面帖子中:
Where does the word “pragma” come from?
第一楼martin clayton的回答。
yisikaipu 2012-08-28
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 的回复:]咬文嚼字:

原意 ... based on practical rather than theoretical considerations
可以对应到 implementation-dependent

所以我的理解是
#pragma 原意是 此处指令依据具体实现[/Quote]

不仅是原意,也是现在的意思。但我想知道的是,为什么用这么个高深的词而不用更易懂的词,诸如#specific
yisikaipu 2012-08-28
  • 打赏
  • 举报
回复
咬文嚼字:

原意 ... based on practical rather than theoretical considerations
可以对应到 implementation-dependent

所以我的理解是
#pragma 原意是 此处指令依据具体实现

牛津词典

pragmatic
adjective

1, dealing with things sensibly and realistically in a way that is based on practical rather than theoretical considerations
讲究实际的,讲求实效的,实干的

2, relating to philosophical or political pragmatism
实用主义的

4, (Linguistics)of or relating to pragmatics
(语言学)语用的
dic_008 2012-08-28
  • 打赏
  • 举报
回复
不多说上个例子:

#pragma warning(disable:4146)
//消除该类型的警告,不显示警告4146

ADO连接数据库经常出现4146警告,告诉编译器忽略它不显示
yisikaipu 2012-08-28
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]我一直以为pragma是两个单词的缩写,后来查了才知道是
源于ada语言的pragmatic information"的简称[/Quote]

这个我知道,wiki上就有提到,但没说源于。源于是你的推断,还是另有文献?

另外,这里的 pragmatic 何意?

myjackheroes 2012-08-28
  • 打赏
  • 举报
回复
我一直以为pragma是两个单词的缩写,后来查了才知道是
源于ada语言的pragmatic information"的简称
franzhong 2012-08-28
  • 打赏
  • 举报
回复
program 演变的?
我怎么感觉两个单词一样呐
yisikaipu 2012-08-28
  • 打赏
  • 举报
回复
莫非这个单词 pragma 本来就有现在的意思?
yisikaipu 2012-08-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]引用 2 楼 的回复:

pragma:注解,注释,编译指示

++
字典就能解决[/Quote]

请先搞清楚我在问什么

两个线索
1, pragmatic 实用
2, pragmatics 语用

#pragma 的原意究竟是什么,是谁最早这么用的
竞天问 2012-08-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

pragma:注解,注释,编译指示
[/Quote]
++
字典就能解决
Gloveing 2012-08-28
  • 打赏
  • 举报
回复
pragma:注解,注释,编译指示
冻结 2012-08-28
  • 打赏
  • 举报
回复
坐沙发上等典故。

64,635

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧