Espaços nominais
Variantes
Acções

Preprocessador

Da cppreference.com
< cpp
 
 
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)
Conversões
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 preprocessador é executado na fase de tradução 4, antes da compilação. O resultado do preprocessamento é um único arquivo que é passado para o compilador de fato.

Índice

[editar] Diretivas

As diretivas de preprocessamento controlam o comportamento do preprocessador. Cada diretiva ocupa uma linha e tem o seguinte formato:

  • caractere #
  • instrução de preprocessamento (um de define, undef, include, if, ifdef, ifndef, else, elif, endif, line, error, pragma)[1]
  • argumentos (depende da instrução)
  • quebra de linha

A diretiva nula (# seguido por uma quebra de linha) é permitida, mas não tem nenhum efeito.

As diretivas module e import também são diretivas de preprocessamento.


(desde C++20)

Diretivas de preprocessamento não podem vir de uma expansão de macro.

#define VAZIO
VAZIO   #   include <file.h> // não é uma diretiva de preprocessamento

[editar] Capacidades

O preprocessador tem as capacidades de tradução de arquivo fonte:

  • condicionalmente compilar partes do arquivo fonte (controlada pelas diretivas #if, #ifdef, #ifndef, #else, #elif e #endif)
  • substituir macros de texto e possivelmente concatenar ou citar identificadores (controlada pelas diretivas #define e #undef, e operadores # e ##)
  • incluir outros arquivos (controlada pela diretiva #include e verificado com __has_include (desde C++17))
  • causar um erro (controlada pela diretiva #error)

Os seguintes aspectos do preprocessador podem ser controlados:

[editar] Notas de rodapé

  1. Estas são as direivas definidas pelo padrão. O padrão não define comportamento para outras diretivas: elas podem ser ignoradas, ter algum significado útil, ou causar um erro de tempo de compilação. Mesmo se do contrário ignoradas, elas são removidas do código fonte quando o preprocessador terminar. Uma extensão não-padrão comum é a diretiva #warning que emie uma mensagem definida pelo usuário durante a compilação.

[editar] Veja também

Documentação C para preprocessador