为什么,我们什么时候需要使用#pragma [英] Why and when do we need to use #pragma

查看:262
本文介绍了为什么,我们什么时候需要使用#pragma的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习一个winsock客户端服务器程序,并通过 #pragma comment(lib,ws2_32.lib)。在这里了解它的需要。

解决方案

我们可以使用它, #pragma 是实现定义的编译器命令。



这意味着,每个编译器都可以用不同的方式处理或支持pragmas。 >

它们用于生成用户定义的警告或错误,例如:



#pragma warning WARNINGMSG



#pragma错误ERRORMSG



或作为包含警告与 #pragma once 在头文件的顶部。



#pragma comment 用于,您可以找到很好解释在这里:



#pragma评论是什么意思?



但是毕竟,我建议你尽可能避免使用pragma,因为它们几乎都是实现定义的,如果你使用它们,你的代码将在可移植性上受到限制。


I was learning a winsock client server program and came up through #pragma comment(lib,"ws2_32.lib"). Understood its need here. But what are the other instances I can use it and why do I need to use it?

解决方案

#pragma 's are implementation defined compiler commands.

That means, each compiler could treat or support pragmas in a different way.

They are used for example for generating user defined warnings or errors as with

#pragma warning WARNINGMSG

or #pragma error ERRORMSG

or as include guard with #pragma once at the top of a headerfile.

What #pragma comment is used for, you can find nice explained here:

What does #pragma comment mean?

But after all, I would advise you to avoid pragmas as far it is possible, because as they are almost all, implementation defined, your code will be limited in portability if you use them.

这篇关于为什么,我们什么时候需要使用#pragma的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆