87969

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

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?

Answer1:

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

Recommend

  • Can I hook into ActiveRecord connection establishment?
  • What is the scope of a pragma directive?
  • Does FENV_ACCESS pragma exist in C++11 and higher?
  • a concept similar to pointers in as3?
  • Python Paramiko send CTRL+C to an ssh shell
  • LNK1104: cannot open file 'kernel32.lib'
  • Recreate the Oracle DUAL table
  • How dotnet build chooses the output name
  • Invert string in Rust
  • Microsoft Excel Pivot miscalculation in Sum for positive and negative numbers
  • Unable to click on the next page button containing “>” sign
  • Is there a way to set up a fallback for the formAction attribute in HTML5?
  • Less Conflicting Session Manager for Zope 2
  • Can you pass an array from javascript to asp.net mvc controller action without using a form?
  • What's the syntax to inherit documentation from another indexer?
  • Can I use AllJoyn Framework for Wifi Direct in iOS?
  • abstracting over a collection
  • Can't remove headers after they are sent
  • Enabling DTD support in Sql Server
  • Subclassing QGraphicsItem prevents me from being able to use itemAt() on a QGraphicsScene/View
  • Do I need to seed any random number generator before using EVP_PKEY_keygen of OpenSSL?
  • calculate gradient output for Theta update rule
  • C++ pointer value changes with static_cast
  • WPF ICommand CanExecute(): RaiseCanExecuteChanged() or automatic handling via DispatchTimer?
  • uniform generation of points on 3D box
  • How to get Eclipse Oxygen to run on Java 9
  • Why Encoding.ASCII != ASCIIEncoding.Default in C#?
  • How to Cache Real-time Data?
  • Installing Apache MyFaces 2 on WildFly 8.2.0
  • Hardware Accelerated Image Scaling in windows using C++
  • one Local Olampyad Questions on Informatic in 2011
  • Can I make an Android app that runs a web view in Chrome 39?
  • Statically linking a C++ library to a C# process using CLI or any other way
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • How to include full .NET prerequisite for Wix Burn installer
  • KeystoneJS: Relationships in Admin UI not updating
  • C# - Getting references of reference
  • -fvisibility=hidden not passed by compiler for Debug builds
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Net Present Value in Excel for Grouped Recurring CF