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

那年仲夏 提交于 2019-12-06 05:58:45
dhein

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

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