Espaços nominais
Variantes
Acções

Conditional inclusion

Da cppreference.com

 
 
Linguagem C + +
Tópicos gerais
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Controle de fluxo
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Declarações execução condicional
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Instruções de iteração
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Ir declarações
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funções
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
declaração da função
lambda declaração da função
modelo de função
linha especificador
especificações de exceção (obsoleta)
noexcept especificador (C++11)
Exceções
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Namespaces
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipos
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decltype specifier (C++11)
Especificadores
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
cv especificadores
armazenamento duração especificadores
constexpr especificador (C++11)
auto especificador (C++11)
alignas especificador (C++11)
Inicialização
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Literais
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expressões
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
representações alternativas
Utilitários
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipos
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
tipo de alias declaração (C++11)
atributos (C++11)
Lança
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversões implícitas
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Elenco C-estilo e funcional
Alocação de memória
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Classes
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Classe propriedades específicas de função
Original:
Class-specific function properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funções membro especiais
Original:
Special member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Modelos
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
modelo de classe
modelo de função
especialização de modelo
pacotes de parâmetros (C++11)
Diversos
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Assembly embutido
 
 
O pré-processador suporta a compilação condicional de partes do arquivo de origem. Este comportamento é controlado por #if, #else, #elif, #ifdef, #ifndef e #endif directivas.
Original:
The preprocessor supports conditional compilation of parts of source file. This behavior is controlled by #if, #else, #elif, #ifdef, #ifndef and #endif directives.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Índice

[editar] Sintaxe

#if expression
#elif expression
#ifdef expression
#ifndef expression
#else expression
#endif expression

[editar] Explicação

O bloco de pré-processamento condicional começa com #if, #ifdef ou directiva #ifndef, então opcionalmente inclui qualquer número de directivas #elif e, opcionalmente, inclui mais de uma directiva #else e é encerrado com a directiva #endif. Quaisquer blocos de pré-processamento condicional internos são tratados separadamente.
Original:
The conditional preprocessing block starts with #if, #ifdef or #ifndef directive, then optionally includes any number of #elif directives, then optionally includes at most one #else directive and is terminated with #endif directive. Any inner conditional preprocessing blocks are processed separately.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cada um #if, #elif, #else, #ifdef e #ifndef directivas bloco de código de controle até que primeiro #elif, #else, #endif directiva não pertencentes a qualquer internas blocos de pré-processamento condicional.
Original:
Each of #if, #elif, #else, #ifdef and #ifndef directives control code block until first #elif, #else, #endif directive not belonging to any inner conditional preprocessing blocks.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#if, #ifdef e #ifndef directivas testar a condição especificada (ver abaixo) e se avalia a verdade, compila o bloco de código controlado. Nesse caso subseqüente #else e directivas #elif são ignorados. Caso contrário, se a condição especificada avalia falsa, o bloco de código controlado é ignorada ea subsequente #else ou #elif directiva (se houver) é processado. No primeiro caso, o bloco de código controlado pela directiva #else é incondicionalmente compilado. Neste último caso, a directiva #elif age como se fosse #if directiva: verifica condição, compila ou ignora o código de bloqueio controlado com base no resultado, e no último caso, os processos subsequentes e #elif #else directivas. O bloco de pré-processamento condicional é denunciado por directiva #endif.
Original:
#if, #ifdef and #ifndef directives test the specified condition (see below) and if it evaluates to true, compiles the controlled code block. In that case subsequent #else and #elif directives are ignored. Otherwise, if the specified condition evaluates false, the controlled code block is skipped and the subsequent #else or #elif directive (if any) is processed. In the former case, the code block controlled by the #else directive is unconditionally compiled. In the latter case, the #elif directive acts as if it was #if directive: checks for condition, compiles or skips the controlled code block based on the result, and in the latter case processes subsequent #elif and #else directives. The conditional preprocessing block is terminated by #endif directive.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Avaliação da condição

[editar] #if, #elif

O expression é uma expressão constante, usando apenas literais e identificadores, definidos usando directiva #define. Qualquer identificador, o que não é literal, não definida usando directiva #define, avalia a 0.
Original:
The expression is a constant expression, using only literais and identifiers, defined using #define directive. Any identifier, which is not literal, non defined using #define directive, evaluates to 0.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
A expressão pode conter operadores unários em forma defined identifier ou defined (identifier) que retornam 1 se o identifier foi definido utilizando #define directiva e 0 contrário. Se o expression avalia a valor diferente de zero, o bloco de código controlado incluído e pulado o contrário. Se qualquer identificador utilizado não é uma constante, que é substituído com 0.
Original:
The expression may contain unary operators in form defined identifier or defined (identifier) which return 1 if the identifier was defined using #define directive and 0 otherwise. If the expression evaluates to nonzero value, the controlled code block is included and skipped otherwise. If any used identifier is not a constant, it is replaced with 0.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] #ifdef, #ifndef

Verifica se o identificador foi definido utilizando directiva #define.
Original:
Checks if the identifier was defined using #define directive.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#ifdef identifier é essencialmente equivalente a #if defined( identifier).
Original:
#ifdef identifier is essentially equivalent to #if defined( identifier).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#ifndef identifier é essencialmente equivalente a #if !defined( identifier).
Original:
#ifndef identifier is essentially equivalent to #if !defined( identifier).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Exemplo

#define ABCD 2
#include <iostream>
 
int main()
{
 
#ifdef ABCD
    std::cout << "1: yes\n";
#else
    std::cout << "1: no\n";
#endif
 
#ifndef ABCD
    std::cout << "2: no1\n";
#elif ABCD == 2
    std::cout << "2: yes\n";
#else
    std::cout << "2: no2\n";
#endif
 
#if !defined(DCBA) && (ABCD < 2*4-3)
    std::cout << "3: yes\n";
#endif
}

Output:

1: yes
2: yes
3: yes