If defined win32 defined windows

#ifdef _WIN32 что это?

Что такое __SC__ в #ifdef?
В одном из исходников есть такой код #ifdef __SC__ typedef long long LONGLONG; #else typedef.

Что это за знак >> прочитал что это сдвиг вправо? что он делает
int d=6, c=5,f; f = d >> c; cout 4

Тематические курсы и обучение профессиям онлайн
Профессия Разработчик на C++ (Skillbox)
Архитектор ПО (Skillbox)
Профессия Тестировщик (Skillbox)

Заказываю контрольные, курсовые, дипломные и любые другие студенческие работы здесь или здесь.

Не могу понять, что это за реализация ORM и как это работает
Есть проект на C#, есть база данных MSSQL, есть код, который позволяет мне добавлять и удалять.

При загрузке компа появляется это, не знаете что это и как исправить
при загрузке компа появляется это, не знаете что это и как исправить

Что это может быть? или как это называется? Меня взломали!
Доброго дня всем, мне по майл.ру.агент отправили сообщением так: Витя Гасай (08.03.2011 23:29).

Ошибка при компиляции JAVA. error: ‘;’ expected Что это и как это исправить?
Добрый день. В первый раз в жизни пытаюсь скомпилировать примитивную программу Example.java, но.

Which Cross Platform Preprocessor Defines? (__WIN32__ or __WIN32 or WIN32 )?

I often see __WIN32 , WIN32 or __WIN32__ . I assume that this depends on the used preprocessor (either one from visual studio, or gcc etc).

Do I now have to check first for os and then for the used compiler? We are using here G++ 4.4.x, Visual Studio 2008 and Xcode (which I assume is a gcc again) and ATM we are using just __WIN32__ , __APPLE__ and __LINUX__ .

5 Answers 5

It depends what you are trying to do. You can check the compiler if your program wants to make use of some specific functions (from the gcc toolchain for example). You can check for operating system ( _WINDOWS, __unix__ ) if you want to use some OS specific functions (regardless of compiler — for example CreateProcess on Windows and fork on unix).

Читайте также:  Windows 10 рабочие столы одинаковые

You must check the documentation of each compiler in order to be able to detect the differences when compiling. I remember that the gnu toolchain(gcc) has some functions in the C library (libc) that are not on other toolchains (like Visual C for example). This way if you want to use those functions out of commodity then you must detect that you are using GCC, so the code you must use would be the following:

This article answers your question:

The article is quite long, and includes tables that are hard to reproduce, but here’s the essence:

You can detect Unix-style OS with:

Once you know it’s Unix, you can find if it’s POSIX and the POSIX version with:

You can check for BSD-derived systems with:

and Apple’s operating systems with

Windows with Cygwin

And non-POSIX Windows with:

The full article lists the following symbols, and shows which systems define them and when: _AIX , __APPLE__ , __CYGWIN32__ , __CYGWIN__ , __DragonFly__ , __FreeBSD__ , __gnu_linux , hpux , __hpux , linux , __linux , __linux__ , __MACH__ , __MINGW32__ , __MINGW64__ , __NetBSD__ , __OpenBSD__ , _POSIX_IPV6 , _POSIX_MAPPED_FILES , _POSIX_SEMAPHORES , _POSIX_THREADS , _POSIX_VERSION , sun , __sun , __SunOS , __sun__ , __SVR4 , __svr4__ , TARGET_IPHONE_SIMULATOR , TARGET_OS_EMBEDDED , TARGET_OS_IPHONE , TARGET_OS_MAC , UNIX , unix , __unix , __unix__ , WIN32 , _WIN32 , __WIN32 , __WIN32__ , WIN64 , _WIN64 , __WIN64 , __WIN64__ , WINNT , __WINNT , __WINNT__ .

What’s the difference between the WIN32 and _WIN32 defines in C++

I know that WIN32 denotes win32 compilation but what is _WIN32 used for?

3 Answers 3

WIN32 is a name that you could use and even define in your own code and so might clash with Microsoft’s usage. _WIN32 is a name that is reserved for the implementor (in this case Microsoft) because it begins with an underscore and an uppercase letter — you are not allowed to define reserved names in your own code, so there can be no clash.

To elaborate (Neil Butterworth and blue.tuxedo have already given the correct answer):

  • WIN32 is defined by the SDK or the build environment, so it does not use the implementation reserved namespace
  • _WIN32 is defined by the compiler so it uses the underscore to place it in the implementation-reserved namespace

You’ll find a similar set of dual defines with nearly identical names and similar uses such as _UNICODE / UNICODE , _DEBUG / DEBUG , or maybe _DLL / DLL (I think that only the UNICODE ones get much of any use in their different versions). Though sometimes in these cases (like _UNICODE ), instead of the underscore version being defined by the compiler, they are used to control what the CRT headers do:

  • _UNICODE tells the CRT headers that CRT names which can be either Unicode or ANSI (such as _tcslen() should map to the wide character variant ( wcslen() )
  • UNICODE does something similar for the SDK (maps Win32 APIs to their » W » variants)
Читайте также:  Skidrow dll для windows

Essentially the versions with the underscore are controlled by or used by the compiler team, the versions without the underscore are controlled/used by teams outside of the compiler. Of course, there’s probably going to be a lot overlap due to compatibility with past versions and just general mistakes by one team or the other.

I find it confusing as hell — and find that they are used nearly interchangeably in user code (usually, when you see one defined, you’ll see the other defined in the same place, because if you need one you need the other). Personally, I think that you should use the versions without the underscore (unless you’re writing the compiler’s runtime) and make sure they both get defined (whether via hearers or compiler switches as appropriate) when you’re defining one.

Note that the SDK will define _WIN32 when building for the Mac because the compiler doesn’t, kind of overstepping it’s bounds. I’m not sure what projects use a Win32 API an a compiler targeting the Mac — maybe some version of Office for the Max or something.

C++ compiling on Windows and Linux: ifdef switch [duplicate]

I want to run some c++ code on Linux and Windows. There are some pieces of code that I want to include only for one operating system and not the other. Is there a standard #ifdef that once can use?

The question is indeed a duplicate but the answers here are much better, especially the accepted one.

7 Answers 7

…where the identifier can be:

I know it is not answer but added if someone looking same in Qt

Читайте также:  Windows software problem has caused

In Qt

It depends on the used compiler.

For example, Windows’ definition can be WIN32 or _WIN32 .

And Linux’ definition can be UNIX or __unix__ or LINUX or __linux__ .

This response isn’t about macro war, but producing error if no matching platform is found.

If #error is not supported, you may use static_assert (C++0x) keyword. Or you may implement custom STATIC_ASSERT, or just declare an array of size 0, or have switch that has duplicate cases. In short, produce error at compile time and not at runtime

It depends on the compiler. If you compile with, say, G++ on Linux and VC++ on Windows, this will do :

No, these defines are compiler dependent. What you can do, use your own set of defines, and set them on the Makefile. See this thread for more info.

If defined win32 defined windows

Конструкция типа (директива препроцессора)

Позволяет исключить двойные включения описания классов, и тем самым избежать ошибок типа error C2011, вот например таких:

Идея октлючения повторов заключена в операторе #define вот как можно сделать.

С этого момента существует понятие My это как константа. Везде где вы не поставите My при компиляции на её место будет поставлена единица (1). Наличие подобных определений можно проверять. Вот так:

Вот на основе этого механизма и действует предупреждения повторных включений. Создайте приложение Win32 console, как пустой проект (An empry project) с именем Test. Добавьте в проект файл Test.cpp и код его:

Файл myclass.h и код к нему.

Файл myclass.cpp и код к нему:

Запустите проект на компиляцию и выполнение, Вы получите ошибку о двойном включении класса.

А теперь раскомментируйте конструкции #if !defined в файле myclass.h и всё сработает.

Ну и что скажете Вы 🙂 да подобные ситуации видны. Современные каркасные библиотеки да и любая сложная структура классов часто требует перекрестных включений классов. Вот и думай потом как и что описывать, а подобным образом просто. Если класс описан, то он просто пропустится :-), а если нет, то описание будет включено. Подобные консрукции использует AppWizard для создаваемых приложений. Кроме того подобным образом можно работать с разными версиями классов. Например, сделать объявление константы, а при создании кода учитывать её установку.

Оцените статью