Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the scope of a pragma directive?

Tags:

What is the scope of a pragma directive? For example, if I say #pragma warning(disable: 4996) in a header file A that is included from a different file B, will that also disable all those warnings inside B? Or should I enable the warning at the end of file A again?

like image 881
fredoverflow Avatar asked Feb 22 '11 13:02

fredoverflow


People also ask

What is the use of pragma directive?

Pragma directives are machine-specific or operating system-specific by definition, and are typically different for every compiler. A pragma can be used in a conditional directive, to provide new preprocessor functionality. Or, use one to provide implementation-defined information to the compiler.

Is #pragma a preprocessor directive?

Does preprocessor really do something with #pragma? Yes, it evaluates it in translation phase 4: "Preprocessing directives are executed, macro invocations are expanded, and _Pragma unary operator expressions are executed."

What are pragma statements?

The PRAGMA statement is an SQL extension specific to SQLite and used to modify the operation of the SQLite library or to query the SQLite library for internal (non-table) data.

What is the function of #pragma pre processor directive?

The preprocessor directive #pragma is used to provide the additional information to the compiler in C/C++ language. This is used by the compiler to provide some special features.


1 Answers

It is till the end of the translation unit. Informally, a TU is the source file with its include files.

The usual pattern is this:

#pragma warning (push) //save #pragma warning (disable: xxxx) #pragma warning (disable: yyyy) ...  //code  #pragma warning (pop) //restore prev settings 

for example

//A.h #pragma once #pragma warning (disable: 1234) #include "b.h"  //b.h #pragma once //when included after a.h 1234 will be disabled  //c.cpp #include "a.h" //warnings 1234 from b.h is disabled  //d.cpp #include "b.h" //warnings 1234 from b.h are not disabled #include "a.h" 
like image 110
Armen Tsirunyan Avatar answered Sep 24 '22 05:09

Armen Tsirunyan