All Questions
52 questions
1
vote
0
answers
169
views
Setting GCC target options (AVX2) for static inline variables with a pragma doesn't work?
I'm using AVX2 instruction to initialize static inline variables in my code. But the following does not compile.
#pragma GCC target("avx2")
#include <iostream>
#include <immintrin.h&...
0
votes
1
answer
180
views
What is the equivalent in GCC to MSVC's '#pragma message'?
On MSVC I can issue compilation-time message like so:
#pragma message("...some compilation-time message...")
Is there an equivalent in GCC?
1
vote
1
answer
250
views
Is it possible to tell the compiler to only ignore specific unknown pragma?
I am not sure where I saw it first, but I got used to using #pragma region region name and #pragma endregion to mark sections in class definitions that belong together, like operator implementations.
...
1
vote
2
answers
256
views
Suppressing warnings for a printf-like function in C++
I have a legacy logging printf-like function in C:
namespace legacy
{
void DoLog(const char* format,...);
}
If is only visible if a corresponding macro is defined (this is legacy too):
#ifdef LOG
...
0
votes
1
answer
265
views
How to print defined macros with pragma to get OS version?
Following these related questions (1,2,3), I'm trying to get OS information from the preprocessor as follows:
#include <boost/preprocessor/stringize.hpp>
#ifdef __MACH__
#pragma message ("...
4
votes
0
answers
157
views
Portable way of optimizing a single function or TU by a specific flag in both GCC and Clang
GCC provides two ways of optimizing a function or TU with a specific optimization flag:
[[gnu::optimize("-ffast-math")]]
void foo() { /* ... */ }
#pragma GCC optimize("ffast-math")...
0
votes
1
answer
539
views
Unknown GCC pragmas on Mac
warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma GCC optimize("O3")
I want to enable GCC optimization flags, but they are ignored when i'm compiling code, although they are ...
2
votes
2
answers
2k
views
GCC #pragma or command options
If the compiler has some command-line flags and the code has some pragmas that are incompatible with those flags, which one will be used?
To be clearer: I am compiling with g++ -g -O2 -std=gnu++17 -...
1
vote
0
answers
1k
views
Unknown GCC pragma generates warning in LLVM
I'm using a GCC #pragma like this:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
...
#pragma GCC diagnostic pop
This works great and removes the ...
0
votes
0
answers
1k
views
How to disable fast math for a header file function
How do I disable fast math for a function defined in header file or for the entire source file?
#pragma GCC optimize ("no-fast-math")
Adding the line above to both (source file and header file) ...
1
vote
0
answers
45
views
What are the differences between attributes and pragmas in C++? [duplicate]
I am interested in the context of C++ code, using compilers such as Clang or GCC. We saw attributes such as __attribute__((always_inline)) and also pragmas such as #pragma inline.
Since both of them ...
2
votes
1
answer
1k
views
pragma GCC poison syntax for member function
In GCC (and clang) there is this option to poison a function:
#include <stdio.h>
#pragma GCC poison puts
int main() {
puts("a");
}
What would be the syntax to poison a member function of ...
-1
votes
1
answer
433
views
Strange behavior of #pragma pack
I am facing a strange issue when using #pragma pack.
I have the following structs:
st_a: packed with #pragma pack(1). Size = 1 byte. Contains bitfields.
st_b: packed with #pragma pack(2). Size = 14 ...
1
vote
1
answer
387
views
Can GCC be configured to ignore #pragma directives?
We are compiling and running user submitted C++ programs in a sandbox environment with the following compile command:
g++ -std=gnu++11 -O2 -o program.exe program.cpp
However, it is possible for ...
1
vote
0
answers
676
views
C++ ignoring warnings in a block with macro
I am using gcc 6.2 and want to ignore warnings in a macro. My idea was to do as in the following demo code.
typedef char aligned_char __attribute__((__aligned__));
// disable warning using #pragma ...
2
votes
0
answers
1k
views
Printing function name (to retrieve namespace) from compiler output
I am seeing some really weird errors in a complex file, and I suspect I have some include with namespaces left open, or something similar.
I cannot compile some file to an executable state.
To figure ...
4
votes
2
answers
342
views
How to force GCC to warn about usage of a class function?
Using GCC 4.8.*, when the warning -Wfloat-equal is activated, the compiler warns about strict comparisons between floting point number, like in the following example:
double x = 3.14159;
double y = 1....
1
vote
1
answer
3k
views
How to fix Wunknown-pragmas gcc warning
I have a code snippet, here I have put a #pragma. This gives Wunknown-pragmas warning :
warning: ignoring #pragma warning [-Wunknown-pragmas]
code:
#include<iostream>
using namespace std;
...
3
votes
0
answers
8k
views
How can I suppress a "-fpermissive" error using modern GCC?
I am trying to compile some nonconforming code in C++17, but I am stuck with the following issue.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-fpermissive"
Some code that ...
0
votes
1
answer
194
views
Stop compilation when a template has been used/resolved
This MCVE:
#include <stdio.h>
#include <time.h>
#define MAX_LENGTH_DATETIME 25
template <typename T>
char * convertUnixTimeToChar( time_t unixTime, T )
{
(void) unixTime;
#...
1
vote
1
answer
407
views
GCC no vectorization output?
I am trying to vectorize a loop using ivdep but I'm not getting any output. I looked at the documentation and used the flags mentioned there. This is my code:
int main()
{
int a[100], b[100];
int ...
26
votes
2
answers
11k
views
do I put [[maybe unused]] on function declarations or definitions?
C++17 introduces the attribute [[maybe_unused]].
I assume this a standardized version of GCC and Clang's: __attribute__((unused)).
For unused functions that I don't want to see a warning from,
...
2
votes
1
answer
772
views
In GCC, how to (temporarily) suppress messages from "#pragma message"
I'm getting many messages emitted from #pragma message from the GLM library. Is there a way to suppress these, preferably temporarily (just for that library)?
28
votes
1
answer
11k
views
How to disable all warnings using pragma directives in GCC
I am seeking for a way to suppress all possible warnings that i may get with Gcc with pragma directives. I had made some guard macros that help me silence 3rd party headers from warnings, and for now ...
1
vote
1
answer
1k
views
gcc 4.8.4 "pragma GCC diagnostic not applied"
Using g++ (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
In a pre-compiled-header I have the following:
63 #pragma GCC diagnostic push
64 #pragma GCC diagnostic ignored "-Wunused-variable"
65 #include <...
5
votes
0
answers
2k
views
How to silence #pragma messages from GCC
I am not interested in seeing #pragma messages for my build. It just clutters the output.
I tell this to Clang by passing -Wno-#pragma-messages. However, GCC does not understand that flag and I can ...
5
votes
1
answer
2k
views
`pragma pack(push, 1)` crashes in GCC 4.4.7. Possible compiler bug?
I'm encountering a bug that has me stumped. I've narrowed it down to an issue with the pragma pack command in GCC (specifically RHEL Linux, GCC v.4.4.7) that can be recreated in the small sample case ...
37
votes
1
answer
15k
views
GCC does not honor 'pragma GCC diagnostic' to silence warnings [duplicate]
We recently enabled -Wall for a project. Its enabled when GCC is at 4.7 or above (or Clang) because we can use GCC diagnostic to manage the output from the elevated warnings. We want to manage them ...
130
votes
8
answers
35k
views
Is there a compiler hint for GCC to force branch prediction to always go a certain way?
For the Intel architectures, is there a way to instruct the GCC compiler to generate code that always forces branch prediction a particular way in my code? Does the Intel hardware even support this? ...
0
votes
0
answers
67
views
Clang compiles code in GCC define block [duplicate]
I have the following code:
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#endif
However if I compile my code with ...
6
votes
2
answers
844
views
Discouraged pragma use GCC
Header guards are necessary in nearly all C++ programs, but are a pain when naming conventions are strictly enforced - especially so during refactoring. When using GCC (and many other compilers) we ...
3
votes
1
answer
1k
views
Can I enable vectorization only for one part of the code?
Is there a way to enable vectorization only for some part of the code, like a pragma directive? Basically having as if the -ftree-vectorize is enabled only while compiling some part of the code? ...
1
vote
3
answers
2k
views
gcc equivalent of #pragma comment
I'm trying to write a macro that adds a comment to an executable with the gcc compiler. This is not for linking purposes, I simply want to add text comments. Is there a #pragma comment equivalent in ...
13
votes
2
answers
1k
views
GCC Plugin, add new optimizing pragma
I'm creating a GCC plugin.
I'm trying to create a plugin for a specific loop transformation - unroll loop exactly N (parameter given) times.
I have installed plugins correctly and I can successfully ...
1
vote
0
answers
169
views
What's GCC for #pragma code_seg? [duplicate]
In MSVC, you can rename the .text section in a compiled file with
#pragma code_seg(".text.but_not_really")
At link time, it will be properly merged with the rest of the .text sections. Is there an ...
4
votes
1
answer
5k
views
How do I ignore a particular gcc warning that's [enabled by default]?
I have the following program that prints green text to the terminal:
#include <iostream>
#include <string>
//returns a colored string for terminal output streams
std::string ...
5
votes
2
answers
322
views
Does gcc have a pragma to define file type/compiler?
GCC automatically switches between compilers based on file extension (.c, .cc), by command line parameter (-x) or by calling the appropriate compiler directly (g++ as opposed to gcc, say).
Is there ...
3
votes
1
answer
679
views
"error: too many #pragma options align=reset" on mac with gcc 4.8
I used macports to update gcc to version 4.8.1. I would like to use that version to build libusbx 1.0.17. But when I './configure' and then 'make' libusbx I get "error: too many #pragma options align=...
4
votes
1
answer
3k
views
"pragma GCC diagnostic ignored" has no effect if it's defined in PCH?
I have several diagnostic pragmas in a header file.
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wmissing-braces"
When I compiled this header file as PCH, ...
0
votes
1
answer
70
views
Silly C++ linking trouble in GCC
Sorry for the non-specific question title. On short, here's what I have:
file1.cpp
#include "file1.h"
int main()
{
somefunc();
}
file1.h
#pragma once
#include "file2.h"
int somevar;
file2....
5
votes
1
answer
797
views
Port some code to GCC, have some problems with #pragma directives
I'm trying to compile this code with GCC and I have these #pragma directives that I'm trying to convert to GCC understandable instructions and I just can't figure out how:
#pragma section(".CRT$XCA", ...
2
votes
1
answer
2k
views
Confused by "#pragma GCC diagnostic push/pop"
I'm trying to use "#pragma GCC diagnostic push" and "#pragma GCC diagnostic pop" to turn warnings on for my code and then back off (for example, once the header ends). But the warnings are not getting ...
1
vote
1
answer
642
views
How can I use pragma weak with namespaced functions?
This works:
test1.h
namespace funcs {
extern "C" {
void a();
void b();
void c();
}
}
test1.cpp
namespace funcs {
void (*all[])() = {a, b, c};
}
extern "C" void hang() {
while (...
4
votes
1
answer
699
views
Struct packing in GCC on 32-bit doesn't work?
I have inherited some third-party code in a project. It's comprised of a header file and a binary library without sources, so I cannot just recompile it with different settings.
The header uses a ...
30
votes
3
answers
55k
views
In GCC, how can I mute the '-fpermissive' warning?
I am including a file from a third-party library that raises an error that can be downgraded to a warning with -fpermissive. But because I do not want to "pollute" my compilation log with ...
11
votes
1
answer
21k
views
GCC #pragma message ignored
I am trying to display a compile-time message in GCC, via
#pragma message "hello world"
But when I compile with -Wall it gives the warning
warning: ignoring #pragma message
I'm using GCC 4.2.1 on ...
9
votes
1
answer
7k
views
How to enable optimization in G++ with #pragma
I want to enable optimization in g++ without command line parameter.
I know GCC can do it by writing #pragma GCC optimize (2) in my code.
But it seems won't work in G++.
This page may help: http://...
6
votes
2
answers
4k
views
How to use GCC diagnostic pragma with C++ template functions?
I would like to use g++ and -Werror, so I have now to disable warnings for 3rd-party libraries I have no control of. The solution provided by http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html ...
5
votes
2
answers
7k
views
Create custom #warning flags
I'm building a commercial app, and we are using some GPL code to help us along.
How can I add #warning or #error statements so that when the code is built for debug, it warns, but when we build for ...
7
votes
2
answers
5k
views
C++ pragma GCC system_header directive
What this C++ directive do: "#pragma GCC system_header"?