top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

GNU "cpp -P" portability

0 votes

Is "cpp -P" POSIX? I poked around at

and could find only matches to "preprocessor" rather than "cpp" in the search facility, and so surmise "no", but thought i'd ask here anyway. I suppose a portable workaround would be:

cpp FILENAME | sed '/^#/d'

but have fingers crossed nonetheless...

posted Jun 8, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

2 Answers

+1 vote
Best answer

No, it's much the same as gcc -P, as far as I could tell by looking it up.

answer Jun 8, 2013 by anonymous
0 votes

No "cpp -P" is not POSIX, it's much the same as gcc -P, as far as I could tell by looking it up.

answer Jun 10, 2013 by anonymous
Similar Questions
+2 votes

GCC gives a warning for this program:

int main()
    int x;

test.cpp: In function 'int main()':
test.cpp:3:9: warning: unused variable 'x' [-Wunused-variable]

If I add an "unused" attribute with the GNU syntax:

int x __attribute__((unused));

the warning goes away.

However, if I use the C++11 syntax:

int x [[unused]];

the warning remains, and I also get:

test.cpp:3:20: warning: 'unused' attribute directive ignored [-Wattributes]

Does anyone know about gcc plans to support the attributes with C++11 syntax.

0 votes

I have the following operator delete replacements:

void operator delete[](void* p)
 /* Implementation does not matter. */

void operator delete[](void* p, std::size_t size)
 /* Implementation does not matter. */

My question is why, in the following code, GCC 6.2 calls void operator delete[](void*) and not the second replacement:

char* str = new char[14];
delete[] str;

According to 5.3.5 Delete [expr.delete]:
(10.3) If the type is complete and if, for the second alternative (delete array) only, the operand is a pointer to a class type with a non-trivial destructor or a (possibly multi-dimensional) array thereof, the function with a parameter of type std::size_t is selected.

Therefore, I believe operator delete[](void*, std::size_t) must be called, doesn't it?

+1 vote

I wanted to ask what is the GCC C++ equivalent implementation of Windows _ MyFirst and _MyLast vector pointers?

These give direct access to the vectors first and last element, but they are not present in the GCC implementation of the vector class.

+1 vote

I have an oversight in my code where I'm declaring & defining a function
with C-linkage, though it's not possible.

Example snippet:

#ifdef __cplusplus
extern "C"

// ... some functions which are compatible with C linkage

// Intended to be a helper function not exposed from library
std::string GetEngineVersion()
 // ...

#ifdef __cplusplus

Obviously the GetEngineVersion function cannot have C linkage because it returns a C++ class.

My question is: does GCC have a warning for this scenario? Specifically, can it warn when something is declared extern "C" that's incompatible with C linkage?

I compile with the following warning flags and I didn't get a warning:

-Wall -Wunused-parameter -Wextra -Weffc++ -Wctor-dtor-privacy
-Wnon-virtual-dtor -Wreorder -Wold-style-cast -Woverloaded-virtual

Incidentally, when I compile the same code in VS2013 I get this warning:

warning C4190: 'GetEngineVersion' has C-linkage specified, but returns UDT 'std::basic_string' which is incompatible with C
+1 vote

I am building a shared library which will be distributed to clients in binary form only. I am attempting to make the same binary run on as many Linux variants as possible, and so when I build it I specify the
options -shared and -fPIC. As part of the effort of making the library as independent as possible, I also link both the C and C++ standard libraries statically into the final shared library. I want to do this because I use
C++11 features internally, and I don't want to force the users of my library to have a C++11 compiler handy.

When doing this, do I need to build libstdc++ and libgcc from source with -fPIC as well? Or is it okay to link with the static versions of these libraries that are provided in my Ubuntu 13.04 gcc package?

To clarify, no exceptions are thrown over library boundaries; all exceptions used internally in the library are caught and processed behind the scenes. None of them ever reach the client code, as the client communicates with the library using a plain C interface.

My exact build flags are as follows:

g++ -fvisibility=hidden -fvisibility-inlines-hidden -static-libstdc++ -static-libgcc -s -DNDEBUG -std=c++11 -Wall -shared -fPIC -o test.cpp -lpthread -O2

Useful Links with Similar Problem
Contact Us
+91 9880187415
#470/147, 3rd Floor, 5th Main,
HSR Layout Sector 7,
Bangalore - 560102,
Karnataka INDIA.