Why and when do we need to use #pragma [closed]

妖精的绣舞 提交于 2019-12-08 01:15:36

问题


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?


回答1:


#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.



来源:https://stackoverflow.com/questions/18656285/why-and-when-do-we-need-to-use-pragma

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!