What are the practical differences between C compilers on Windows?

A program written in Visual C / C ++ 2005/2008 may not compile with another compiler such as GNU C / C ++ or vice versa. For example, when trying to reuse code that uses windows.h written for a specific compiler with another, what differences do you need to know?

Is there any information on how to create code that is compatible with either one compiler or another, for example. with GC / C ++ or MSVC / C ++? What problems will try to do this?

What about other compilers like LCC and Digital Mars?

+3
source share
7 answers

, , MSVC, - Microsoft. ( /Za, ). , GCC .

, Windows API (MFC, Win32 ..) Windows, "" " " .

+7

, , - , - HTML?

.

, GCC -std = c89 ( -std = ++ 98 ++), -pedantic -Wall, plus -Wextra, , , - GNU, -pedantic ( ), C89. ++ , , .

C89 (//, , , stdint.h , , 64- ..), , . , , GCC MSVC, , MSVC. " ". , , "inline" "inline" GCC MSVC/++, "__inline" MSVC/C. MSVC stdint.h .

- , GCC. , , Windows XP Mobile. " " , . , , 64- .

Windows, -, , , , , , , , GCC . , , , .

. # Windows API windows.h, , , linux, , KDE GCC, MSVC.

, , , . , API- , POSIX ( ), , "", . , API-, Windows, GCC/linux, AFIAK. WINE, .

+5

"" "". < windows.h > , MSVC C : C- Windows API. Visual Studio. C Windows, , . Linux, , < unistd.h > , < pthereads.h > . GCC, , Linux, .

, : C , ? ?

+5

, . , , , (msvc 8/Windows, gcc 4.2/Linux, gcc 3.4/ ARM9-). Visual Studio 2005.

a) , Windows, , windows.h. "windows_types.h" :

#ifndef _WIN32
    typedef short              INT16;
    typedef unsigned short     UINT16;
    typedef int                INT32;
    typedef unsigned int       UINT32;
    typedef unsigned char      UCHAR;
    typedef unsigned long long UINT64;
    typedef long long          INT64;
    typedef unsigned char      BYTE;
    typedef unsigned short     WORD;
    typedef unsigned long      DWORD;
    typedef void *             HANDLE;
    typedef long               LONG;
#endif

, , , Windows.

b) typename . MSVC ( , ). .

c) , : Windows , #include , Linux.

d) , Windows API. , CRITICAL_SECTIONS INTERLOCKED_INCREMENT. , , .

e) , . pch gcc3.4, , .h/cpp ( ).

f) VS 2005 . auto_ptr , . ( !) gcc, .

g) , , . . gcc , VS 2005 . .

h) VS 2005 std:: exception . gcc . , .

, , !

+5

, . , MSVC C , ++ compliance . Howerver "windows" C MSVC, gcc, . , ANSI C99, "" gcc MSVC.

MSVC- > gcc, . , , . Windows MSVC, , gcc.

LCC - , AFAIKT ANSI C99, MSVC. LCC "" .

lcc-win32 - C, ANSI C99. , IDE ..

Digital Mars

Pelles-C, IDE.

OpenWatcom. - , , .

"" MSVC → , , , .

Friedrich

+4

, Visual C/++ 2005/2008, , GNU C/++ .

, (1) - , , ( ++, , typename template , - Visual ++, ; gcc , 3.4) (2) , , ( - - , , Visual ++ gcc ).

, , windows.h, ,

. Microsoft windows.h gcc. gcc windows.h gcc Microsoft windows.h Visual ++, . " windows.h" .

, ?

, , , template/typename , . , , gcc , , Visual ++, gcc , .

++ 0x. gcc, Visual ++ .

+1
source

vs2008 has a lot more standards than in 2005.
I had more problems with a different path, especially with the "function" gcc, which allows you to allocate an array with a variable size at runtime "int array [variable]", which is just pure evil.

+1
source

Source: https://habr.com/ru/post/1699652/


All Articles