| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3210 人关注过本帖
标题:[求助]关于#pragram 的用法
只看楼主 加入收藏
czl
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2007-7-1
收藏
 问题点数:0 回复次数:6 
[求助]关于#pragram 的用法
希望知道的人详细解释一下 包括在什么环境下用
搜索更多相关主题的帖子: pragram 用法 环境 解释 
2007-08-11 12:15
雨中飞燕
Rank: 3Rank: 3
等 级:禁止访问
威 望:8
帖 子:2200
专家分:0
注 册:2007-8-9
收藏
得分:0 
没见过#pragram
只见过#pragma
2007-08-11 12:31
czl
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2007-7-1
收藏
得分:0 

我的手误 多谢LS

2007-08-11 14:46
lishizelibin
Rank: 2
等 级:论坛游民
帖 子:513
专家分:41
注 册:2007-5-10
收藏
得分:0 

Pragma是什么?
翻译:Rogers后附英文原文。


(译者注:
一句话,pragma就是为了让编译器编译出的C或C++程序与机器硬件和操作系统保持完全兼容而定义的宏扩展,
#pragma是和特定编译器相关的。)
两部分:
1.Pragma说明;
2.Pragma的语法。

一、Pragma说明(Directives)

C和C++程序的每次执行都支持其所在的主机或操作系统所具有的一些独特的特点。
一些程序,例如,需要精确控制数据存放的内存区域或控制某个函数接收的参数。
#pragma指示为编译器提供了一种在不同机器和操作系统上编译以保持C和C++完全兼容的方法。?
Pragmas是由机器和相关的操作系统定义的,通常对每个编译器来说是不同的。


二、语法(Syntax)

#pragma token-string(特征字符串)

特征字符串是一连串的字符,就是要给一个特定编译器提供说明和编译意见。

符号(#)必须是pragma所在那一行的第一个非空格字符;
#号和pragma之间可以有任意个空格符。
在#pragma之后,是可以被编译器解析的预处理特征字符。
一般认为,#pragma属于宏扩展。
如果编译器发现不认识的pragma,会提出警告,但继续编译下去。

Pragmas可以用在条件声明上,提供最新的功能性的预处理程序,或者提供给编译器定义执行的信息。
C和C++编译器认可如下pragmas:
alloc_text
comment //注释
init_seg1
optimize //最优化
auto_inline
component //组成部件
inline_depth
pack //包
bss_seg
data_seg
inline_recursion //内嵌递归
pointers_to_members1
check_stack
function
intrinsic //内在的
setlocale
code_seg
hdrstop
message
vtordisp1
const_seg
include_alias
once
warning


这是MSDN的一篇文章,原作者曾经想使用
#pragma pack(1) // 用GCC在MIPS平台上将结构体成员结合到一块连续的内存块,但是没有做到。

在linux环境下使用intel-based GCC,#pragma pack(1)可以工作。

建议参考具体编译器的文档,在里面应该有pragma的说明。

---------------------------------------原文-------------------------------------------

Pragma Directives
Each implementation of C and C++ supports some features unique to its host machine or operating system.

Some programs, for instance, need to exercise precise control over the memory areas where data is placed 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.

Syntax

#pragma token-string

The token-string is a series of characters that gives a specific compiler instruction and arguments,
if any.

The number sign (#) must be the first non-white-space character on the line containing the pragma;

white-space characters can separate the number sign and the word pragma.
Following #pragma, write any text that the translator can parse as preprocessing tokens.
The argument to #pragma is subject to macro expansion.

If the compiler finds a pragma it does not recognize, it issues a warning, but compilation continues.

Pragmas can be used in conditional statements, to provide new preprocessor functionality,
or to provide implementation-defined information to the compiler.
The C and C++ compilers recognize the following pragmas:

alloc_text comment init_seg1 optimize
auto_inline component inline_depth pack
bss_seg data_seg inline_recursion pointers_to_members1
check_stack function intrinsic setlocale
code_seg hdrstop message vtordisp1
const_seg include_alias once warning


This is an article from MSDN, I ever wanted to use
#pragma pack(1) //which can combine structure members to one continuous memory block
on MIPS platform using GCC, but it doesn't work.


See the compiler's document, it should be illustrated there.

Under linux env using intel-based GCC, it works.


惟有学习不断的学习!
2007-08-11 15:23
雨中飞燕
Rank: 3Rank: 3
等 级:禁止访问
威 望:8
帖 子:2200
专家分:0
注 册:2007-8-9
收藏
得分:0 

MSDN有适于这个的很详细的文档啊

2007-08-11 16:34
缘吇弹
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:地球
等 级:版主
威 望:43
帖 子:3038
专家分:27
注 册:2007-7-2
收藏
得分:0 
以下是引用lishizelibin在2007-8-11 15:23:03的发言:

Pragma是什么?
翻译:Rogers后附英文原文。


(译者注:
一句话,pragma就是为了让编译器编译出的C或C++程序与机器硬件和操作系统保持完全兼容而定义的宏扩展,
#pragma是和特定编译器相关的。)
两部分:
1.Pragma说明;
2.Pragma的语法。

一、Pragma说明(Directives)

C和C++程序的每次执行都支持其所在的主机或操作系统所具有的一些独特的特点。
一些程序,例如,需要精确控制数据存放的内存区域或控制某个函数接收的参数。
#pragma指示为编译器提供了一种在不同机器和操作系统上编译以保持C和C++完全兼容的方法。?
Pragmas是由机器和相关的操作系统定义的,通常对每个编译器来说是不同的。


二、语法(Syntax)

#pragma token-string(特征字符串)

特征字符串是一连串的字符,就是要给一个特定编译器提供说明和编译意见。

符号(#)必须是pragma所在那一行的第一个非空格字符;
#号和pragma之间可以有任意个空格符。
在#pragma之后,是可以被编译器解析的预处理特征字符。
一般认为,#pragma属于宏扩展。
如果编译器发现不认识的pragma,会提出警告,但继续编译下去。

Pragmas可以用在条件声明上,提供最新的功能性的预处理程序,或者提供给编译器定义执行的信息。
C和C++编译器认可如下pragmas:
alloc_text
comment //注释
init_seg1
optimize //最优化
auto_inline
component //组成部件
inline_depth
pack //包
bss_seg
data_seg
inline_recursion //内嵌递归
pointers_to_members1
check_stack
function
intrinsic //内在的
setlocale
code_seg
hdrstop
message
vtordisp1
const_seg
include_alias
once
warning


这是MSDN的一篇文章,原作者曾经想使用
#pragma pack(1) // 用GCC在MIPS平台上将结构体成员结合到一块连续的内存块,但是没有做到。

在linux环境下使用intel-based GCC,#pragma pack(1)可以工作。

建议参考具体编译器的文档,在里面应该有pragma的说明。

---------------------------------------原文-------------------------------------------

Pragma Directives
Each implementation of C and C++ supports some features unique to its host machine or operating system.

Some programs, for instance, need to exercise precise control over the memory areas where data is placed 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.

Syntax

#pragma token-string

The token-string is a series of characters that gives a specific compiler instruction and arguments,
if any.

The number sign (#) must be the first non-white-space character on the line containing the pragma;

white-space characters can separate the number sign and the word pragma.
Following #pragma, write any text that the translator can parse as preprocessing tokens.
The argument to #pragma is subject to macro expansion.

If the compiler finds a pragma it does not recognize, it issues a warning, but compilation continues.

Pragmas can be used in conditional statements, to provide new preprocessor functionality,
or to provide implementation-defined information to the compiler.
The C and C++ compilers recognize the following pragmas:

alloc_text comment init_seg1 optimize
auto_inline component inline_depth pack
bss_seg data_seg inline_recursion pointers_to_members1
check_stack function intrinsic setlocale
code_seg hdrstop message vtordisp1
const_seg include_alias once warning


This is an article from MSDN, I ever wanted to use
#pragma pack(1) //which can combine structure members to one continuous memory block
on MIPS platform using GCC, but it doesn't work.


See the compiler's document, it should be illustrated there.

Under linux env using intel-based GCC, it works.


介绍挺详细的


Repeat  Life=Study;Until (death);
2007-08-11 16:38
wu516966411
Rank: 1
来 自:怀化
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-5-10
收藏
得分:0 
以下是引用lishizelibin在2007-8-11 15:23:03的发言:


Pragma是什么?
翻译:Rogers后附英文原文。
 


(译者注:
一句话,pragma就是为了让编译器编译出的C或C++程序与机器硬件和操作系统保持完全兼容而定义的宏扩展,
#pragma是和特定编译器相关的。)
两部分:
1.Pragma说明;
2.Pragma的语法。
 

一、Pragma说明(Directives)
 

C和C++程序的每次执行都支持其所在的主机或操作系统所具有的一些独特的特点。
一些程序,例如,需要精确控制数据存放的内存区域或控制某个函数接收的参数。
#pragma指示为编译器提供了一种在不同机器和操作系统上编译以保持C和C++完全兼容的方法。?
Pragmas是由机器和相关的操作系统定义的,通常对每个编译器来说是不同的。
 


二、语法(Syntax)
 

#pragma token-string(特征字符串)
 

特征字符串是一连串的字符,就是要给一个特定编译器提供说明和编译意见。
 

符号(#)必须是pragma所在那一行的第一个非空格字符;
#号和pragma之间可以有任意个空格符。
在#pragma之后,是可以被编译器解析的预处理特征字符。
一般认为,#pragma属于宏扩展。
如果编译器发现不认识的pragma,会提出警告,但继续编译下去。
 

Pragmas可以用在条件声明上,提供最新的功能性的预处理程序,或者提供给编译器定义执行的信息。
C和C++编译器认可如下pragmas:
alloc_text
comment //注释
init_seg1  
optimize  //最优化
auto_inline
component  //组成部件
inline_depth
pack       //包
bss_seg
data_seg
inline_recursion  //内嵌递归
pointers_to_members1
check_stack
function   
intrinsic  //内在的
setlocale
code_seg
hdrstop
message  
vtordisp1
const_seg
include_alias
once
warning
 


这是MSDN的一篇文章,原作者曾经想使用
#pragma pack(1) // 用GCC在MIPS平台上将结构体成员结合到一块连续的内存块,但是没有做到。
 

在linux环境下使用intel-based GCC,#pragma pack(1)可以工作。
 

建议参考具体编译器的文档,在里面应该有pragma的说明。
 

---------------------------------------原文-------------------------------------------
 

Pragma Directives
Each implementation of C and C++ supports some features unique to its host machine or operating system.
 

Some programs, for instance, need to exercise precise control over the memory areas where data is placed 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.
 

Syntax
 

#pragma token-string
 

The token-string is a series of characters that gives a specific compiler instruction and arguments,
if any.
 

The number sign (#) must be the first non-white-space character on the line containing the pragma;
 

white-space characters can separate the number sign and the word pragma.
Following #pragma, write any text that the translator can parse as preprocessing tokens.
The argument to #pragma is subject to macro expansion.
 

If the compiler finds a pragma it does not recognize, it issues a warning, but compilation continues.
 

Pragmas can be used in conditional statements, to provide new preprocessor functionality,
or to provide implementation-defined information to the compiler.
The C and C++ compilers recognize the following pragmas:
 

alloc_text comment init_seg1 optimize
auto_inline component inline_depth pack
bss_seg data_seg inline_recursion pointers_to_members1
check_stack function intrinsic setlocale
code_seg hdrstop message vtordisp1
const_seg include_alias once warning
 


This is an article from MSDN, I ever wanted to use
#pragma pack(1) //which can combine structure members to one continuous memory block
on MIPS platform using GCC, but it doesn't work.
 


See the compiler's document, it should be illustrated there.
 

Under linux env using intel-based GCC, it works.
 

!!~~~~
2013-06-14 13:10
快速回复:[求助]关于#pragram 的用法
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013293 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved