**************************请教几个基本的 C++ 问题,希望得高人详细指点! ^_^

Iforgot 2004-04-12 11:12:28
#pragma 宏到底有什么用啊?能不能详细解释一下。
#line 呢?

__declspec、__event、__cdecl和__stdcall能不能也解释一下?

最好能详细说一下。 谢了。

...全文
204 17 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
积木 2004-04-16
  • 打赏
  • 举报
回复
关于函数调用方式
http://expert.csdn.net/Expert/topic/2940/2940421.xml?temp=.9777796
我发了一些东西在上面是别人写的,希望对你有用
Iforgot 2004-04-16
  • 打赏
  • 举报
回复
最好能说出他们之间的区别和差异。
Iforgot 2004-04-16
  • 打赏
  • 举报
回复
关于 #Pragma 解释 先谢了!

对于函数调用方式的宏能不能详细解释一下?
Iforgot 2004-04-12
  • 打赏
  • 举报
回复
怎么说呢。 我英语不是很差。(当然,还需要好好学习了。^_^)

只是,不太确信。 而且,总决得理解的很别扭。 所以,还希望高人能指点。
happlyman 2004-04-12
  • 打赏
  • 举报
回复
msdn是一定离不开的,英语不好就用翻译软件看吧,多看几次就明白了,里面都是一般现在时,还是比较好明白的。
sharkhuang 2004-04-12
  • 打赏
  • 举报
回复
MSDN
talkingmute 2004-04-12
  • 打赏
  • 举报
回复
哎,英语看来真是很重要的!
我现在有时看那些E文也是很迷茫的。。。
兄弟们啊,英语差的都赶快要补补了,我眼前要先把那英语四级过了!
Iforgot 2004-04-12
  • 打赏
  • 举报
回复
问题是MSDN得E文我看得不准确。 所以,希望各位能给讲解。

我就是在MSDN看不懂,copy过来的。


希望能得到各位的自己的语言的解释。
ghostliu 2004-04-12
  • 打赏
  • 举报
回复
#pragma 是用来给编译器指定一些编译时的行为。比如说:
#pragma warning( disable : 4507 34 ) 是告诉编译器不对4507和34这两个警告做提示。
freefalcon 2004-04-12
  • 打赏
  • 举报
回复
强烈建议看msdn
没有msdn,在网上搜索也行
hslinux 2004-04-12
  • 打赏
  • 举报
回复
找个MSDN,什么都有了。
hslinux 2004-04-12
  • 打赏
  • 举报
回复
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.


The #line Directive
The #line directive tells the preprocessor to change the compiler’s internally stored line number and filename to a given line number and filename. The compiler uses the line number and filename to refer to errors that it finds during compilation. The line number usually refers to the current input line, and the filename refers to the current input file. The line number is incremented after each line is processed.

Syntax

#line

digit-sequence "filename"opt
zzghost 2004-04-12
  • 打赏
  • 举报
回复
积木 2004-04-12
  • 打赏
  • 举报
回复
__declspec、__event、__cdecl和__stdcall
后面的两个宏是定义调用函数方式的,前面的不清楚不敢乱说,嘿嘿
积木 2004-04-12
  • 打赏
  • 举报
回复
__declspec、__event、__cdecl和__stdcall能不能也解释一下?
这个仅仅是几个编译宏而已啊,我知道后面的两个是控制函数调用方式的
前面的两个不是很清楚了
积木 2004-04-12
  • 打赏
  • 举报
回复
在所有的预处理指令中,#Pragma 指令可能是最复杂的了,它的作用是设定编译器的状态或
者是指示编译器完成一些特定的动作。#pragma指令对每个编译器给出了一个方法,在保持与
C和C++语言完全兼容的情况下,给出主机或操作系统专有的特征。依据定义,编译指示是机器
或操作系统专有的,且对于每个编译器都是不同的。
其格式一般为: #Pragma Para
其中Para 为参数,下面来看一些常用的参数。

(1)message 参数。 Message 参数是我最喜欢的一个参数,它能够在编译信息输出窗
口中输出相应的信息,这对于源代码信息的控制是非常重要的。其使用方法为:
#Pragma message(“消息文本”)
当编译器遇到这条指令时就在编译输出窗口中将消息文本打印出来。
当我们在程序中定义了许多宏来控制源代码版本的时候,我们自己有可能都会忘记有没有正
确的设置这些宏,此时我们可以用这条指令在编译的时候就进行检查。假设我们希望判断自
己有没有在源代码的什么地方定义了_X86这个宏可以用下面的方法
#ifdef _X86
#Pragma message(“_X86 macro activated!”)
#endif
当我们定义了_X86这个宏以后,应用程序在编译时就会在编译输出窗口里显示“_
X86 macro activated!”。我们就不会因为不记得自己定义的一些特定的宏而抓耳挠腮了


(2)另一个使用得比较多的pragma参数是code_seg。格式如:
#pragma code_seg( ["section-name"[,"section-class"] ] )
它能够设置程序中函数代码存放的代码段,当我们开发驱动程序的时候就会使用到它。

(3)#pragma once (比较常用)
只要在头文件的最开始加入这条指令就能够保证头文件被编译一次,这条指令实际上在VC6(6)#pragma warning( disable : 4507 34; once : 4385; error : 164 )
等价于:
#pragma warning(disable:4507 34) // 不显示4507和34号警告信息
#pragma warning(once:4385) // 4385号警告信息仅报告一次
#pragma warning(error:164) // 把164号警告信息作为一个错误。
同时这个pragma warning 也支持如下格式:
#pragma warning( push [ ,n ] )
#pragma warning( pop )
这里n代表一个警告等级(1---4)。
#pragma warning( push )保存所有警告信息的现有的警告状态。
#pragma warning( push, n)保存所有警告信息的现有的警告状态,并且把全局警告
等级设定为n。
#pragma warning( pop )向栈中弹出最后一个警告信息,在入栈和出栈之间所作的
一切改动取消。例如:
#pragma warning( push )
#pragma warning( disable : 4705 )
#pragma warning( disable : 4706 )
#pragma warning( disable : 4707 )
//.......
#pragma warning( pop )
在这段代码的最后,重新保存所有的警告信息(包括4705,4706和4707)。
(7)pragma comment(...)
该指令将一个注释记录放入一个对象文件或可执行文件中。
常用的lib关键字,可以帮我们连入一个库文件。

补充一个 #pragma pack 1 将c/c++结构体里面的数据按照1字节对齐。这条指令在通信的时
候很常用。
freefalcon 2004-04-12
  • 打赏
  • 举报
回复
你最好说说哪里不清楚
要全部翻译过来比较费时

或者装个中文版的msdn也行

65,187

社区成员

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

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