Freigeben über


Online C++ Compilation Service

There are many useful online c++ compilation service providers. You can use them to do conformance test and portability test without purchasing and installing various kinds of compilers.

The following sites are the most famous:

Online Judge systems are also good places to do the test:

You may be curious about the compiler version and compile options they use to compile your code. Some sites will show you the information. But some won't. Then you're on your own way to discover the secret.

First, let's check some tricks to ask the compiler to tell us some useful information.

1. Output macro
In C++, string literal can't be used as template argument. Most of the compilers will include the content of the string literal when they generate the error message. The following code snippet shows the magic.

template<const char *> class A {};
#define F0(x) #x
#define F1(x) F0(x)
#define V1 F1(__GNUC__)
int main()
{
    A<V1> a1;
}

Here, macro F0 and F1 are used to convert the integral into string. The compiler will show message like "literal "3" is not a valid template argument because it is the address of an object with static linkage". And "3" is what you want.

2. Output constant
Similarly, float is not allowed as template argument. And the compiler will show the float in the error message. This can be used to output float constant. Unfortunately, VC will implicitly convert float into int when it is used as template argument (see https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=296008 for details)
Here is another trick to output integral constant:

template<int N>
class A
{
private:
    A();
};
int main()
{
    A<sizeof(char)> a;
}

3. Output type
Sometimes, you may not be sure about the type of some variables. Then you can use the following code to detect their type.

struct Dummy {};
void Fun(const Dummy &);
int main()
{
    Fun(1+1U);
}

BTW, gcc will show "not convert `2' to `const Dummy&'", then you can use "template<typename T> void Fun(T);" for the declaration of Fun (that means you can use the above code to output constant in gcc)

4. Find out include path
For STL, you can use

#include <ext/hash_set>
using __gnu_cxx::hash_set; 

int main()
{
    hash_set<> m;
}

vector is OK, too.

Now it's time to find out the compiler information. To find out the compiler version, you can check this page: Pre-defined Compiler Macros

The information of dinkumware online test:

1. VC
Version (_MSC_FULL_VER):
         VC8 140050727
         VC7.1 13103077
         VC7 13009466
         VC6 12008804
Include path:
         D:\cplt501_vc_source\include (with _CPPLIB_VER=501)

2. EDG
Version (__EDG_VERSION__):
         3.05 
Compile option:
         edgcc --alt -D_WIN32 -D_M_IX86 --no_inlining --diag_suppress=1290 --long_long --wchar_t_keyword -D_C99 -ID:\cplt501_gen_source/include/c -ID:\cplt501_gen_source/include -IC:\PROGRA~1\MICROS~2.NET\VC7/include --exceptions --microsoft -c sourceFile.cpp
Because VC compatible mode is used, it may emulate bugs in VC, too

3. GCC
Version:
         3.2.0
Include path:
         D:/cplt501_gen_source/include and D:/Mingw/include/c++/3.2/
This version is really out of date

Comments

  • Anonymous
    September 15, 2008
    The comment has been removed

  • Anonymous
    September 15, 2008
    VC Express is free. And I think both VC and g++ are very excellent C++ compilers

  • Anonymous
    May 04, 2015
    #include<stdio.h> int main(void) { int m,n,i,k; double s=0; n=1; while(v>=0.02){ m=n+2; i=n+1; k=n+3; s=(nm)/(ik)+s; v=s-1; n++; } printf("%.2f",s); return 0; }