Namensräume
Varianten

Replacing text macros

Aus cppreference.com

 
 
Sprache C++
Allgemeine Themen
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.
Flusskontrolle
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.
Bedingte Ausführung Aussagen
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.
Iterationsanweisungen
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.
Gehe Aussagen
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.
Funktionen
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funktion Erklärung
Lambda-Funktion Erklärung
Funktions-Template
inline-Spezifizierer
Exception-Spezifikationen(veraltet)
noexcept Spezifizierer(C++11)
Ausnahmen
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.
Types
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)
Specifiers
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 Planer
Lagerdauer Planer
constexpr Spezifizierer(C++11)
auto Spezifizierer(C++11)
alignas Spezifizierer(C++11)
Initialisierung
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Literale
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expressions
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
alternative Darstellungen
Utilities
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Types
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
Typ Aliasdeklaration(C++11)
Attribute(C++11)
Wirft
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
impliziten Konvertierungen
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-Stil und funktionale Besetzung
Speicherzuweisung
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.
Class-spezifische Funktion Eigenschaften
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.
Besondere Member-Funktionen
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.
Templates
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Klassen-Template
Funktions-Template
Template-Spezialisierung
Parameter Packs(C++11)
Verschiedenes
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Inline Montage
 
 
Der Präprozessor unterstützt Text-Makro-Ersatz. Function-like Textmakro Ersatz wird ebenfalls unterstützt .
Original:
The preprocessor supports text macro replacement. Function-like text macro replacement is also supported.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Inhaltsverzeichnis

[Bearbeiten]Syntax

#defineidentifierreplacement-list (1)
#defineidentifier(parameters)replacement-list (2)
#defineidentifier(parameters, ... )replacement-list (3)
#defineidentifier( ... )replacement-list (4)
#undef identifier (5)

[Bearbeiten]Erklärung

[Bearbeiten]NJ Richtlinien

Die #define Richtlinien definieren die identifier als Makro, das ist den Compiler anweisen, alle aufeinanderfolgenden Vorkommen von identifier mit replacement-list, die gegebenenfalls zusätzlich verarbeitet werden kann ersetzen. Wenn die Kennung bereits als jede Art von Makro definiert, ist das Programm falsch gebildete .
Original:
The #define directives define the identifier as macro, that is instruct the compiler to replace all successive occurrences of identifier with replacement-list, which can be optionally additionally processed. If the identifier is already defined as any type of macro, the program is ill-formed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten]Object-wie Makros
Object-like Makros ersetzen alle Vorkommen von definierten identifier mit replacement-list. Version (1) des #define Richtlinie verhält sich genau wie, dass .
Original:
Object-like macros replace every occurrence of defined identifier with replacement-list. Version (1) of the #define directive behaves exactly like that.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten]Function-wie Makros
Function-like Makros ersetzen jedes Vorkommen von definierten identifier mit replacement-list zusätzlich unter eine Reihe von Argumenten, die dann ersetzt werden entsprechende Ereignisse aus einem der parameters im replacement-list. Die Anzahl der Argumente ist die gleiche wie die Anzahl der Argumente in den Makro-Definition (parameters) oder das Programm ist schlecht gebildet werden. Wenn die Kennung nicht in der funktionalen-Notation, dh nicht Klammern hinter sich, ist es überhaupt nicht ersetzt .
Original:
Function-like macros replace each occurrence of defined identifier with replacement-list, additionally taking a number of arguments, which then replace corresponding occurrences of any of the parameters in the replacement-list. The number of arguments must be the same as the number of arguments in macro definition (parameters) or the program is ill-formed. If the identifier is not in functional-notation, i.e. does not have parentheses after itself, it is not replaced at all.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Version (2) des #define Richtlinie definiert eine einfache Funktion Makroidentifizierer .
Original:
Version (2) of the #define directive defines a simple function-like macro.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Version (3) des #define Richtlinie definiert eine Funktion-wie Makro mit variablen Anzahl von Argumenten. Die zusätzlichen Argumente können über __VA_ARGS__ Kennung, die dann mit Argumenten, mit der Kennung zugeführten Fassung ersetzt werden .
Original:
Version (3) of the #define directive defines a function-like macro with variable number of arguments. The additional arguments can be accessed using __VA_ARGS__ identifier, which is then replaced with arguments, supplied with the identifier to be replaced.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Version (4) des #define Richtlinie definiert eine Funktion-wie Makro mit variablen Anzahl von Argumenten, aber keine regelmäßigen Argumente. Die Argumente können nur mit __VA_ARGS__ Kennung, die dann mit Argumenten, mit Identifier zugeführten Fassung ersetzt ist zugegriffen werden .
Original:
Version (4) of the #define directive defines a function-like macro with variable number of arguments, but no regular arguments. The arguments can be accessed only with __VA_ARGS__ identifier, which is then replaced with arguments, supplied with identifier to be replaced.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten]NJ und NJ Betreiber

In der Funktion-wie Makros, läuft ein # Betreiber vor einer Kennung im replacement-list die Kennung über den Parameter Ersatz-und umschließt das Ergebnis in Anführungszeichen, um damit eine String-Literal. Darüber hinaus fügt der Präprozessor backslahes die Anführungszeichen Umgebung eingebettete Zeichenfolgenliterale zu entkommen, wenn überhaupt, und verdoppelt die Backslashes innerhalb des Strings wie nötig. Alle führenden und abschließenden Leerzeichen entfernt wird, und jede Folge von Leerzeichen in der Mitte des Textes (aber nicht innerhalb eingebettete Zeichenfolgenliterale) auf einen einzigen Raum zusammen. Dieser Vorgang wird als "stringification". Wenn das Ergebnis der stringification ist kein gültiger String-Literal, ist das Verhalten undefiniert .
Original:
In function-like macros, a # operator before an identifier in the replacement-list runs the identifier through parameter replacement and encloses the result in quotes, effectively creating a string literal. In addition, the preprocessor adds backslahes to escape the quotes surrounding embedded string literals, if any, and doubles the backslashes within the string as necessary. All leading and trailing whitespace is removed, and any sequence of whitespace in the middle of the text (but not inside embedded string literals) is collapsed to a single space. This operation is called "stringification". If the result of stringification is not a valid string literal, the behavior is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Ein ## Operator zwischen zwei beliebigen aufeinanderfolgenden Identifikatoren im replacement-list verläuft Parameterersetzung auf den beiden Kennungen und dann das Ergebnis verkettet. Dieser Vorgang wird als "Verkettung" oder "Token einfügen". Nur Token, die ein gültiges Token bilden zusammen können eingefügt werden: Kennungen, die eine längere Kennung bilden, Ziffern, die eine Reihe bilden, oder Betreiber + und = diese Form eine +=. Ein Kommentar kann nicht durch Einfügen / und * erstellt werden, da Kommentare aus Text entfernt werden, bevor Makroersetzung betrachtet. Wenn das Ergebnis der Verkettung ist kein gültiges Token, ist das Verhalten undefiniert .
Original:
A ## operator between any two successive identifiers in the replacement-list runs parameter replacement on the two identifiers and then concatenates the result. This operation is called "concatenation" or "token pasting". Only tokens that form a valid token together may be pasted: identifiers that form a longer identifier, digits that form a number, or operators + and = that form a +=. A comment cannot be created by pasting / and * because comments are removed from text before macro substitution is considered. If the result of concatenation is not a valid token, the behavior is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten]NJ Richtlinie

Die #undef Richtlinie undefines die identifier, die bricht bisherige Definition des identifier durch #define Richtlinie. Wenn der Identifizierer nicht Makro zugeordnet sind, wird die Richtlinie ignoriert .
Original:
The #undef directive undefines the identifier, that is cancels previous definition of the identifier by #define directive. If the identifier does not have associated macro, the directive is ignored.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten]Vordefinierte Makros

Die folgenden Makronamen sind vordefiniert in einer Übersetzung Einheit .
Original:
The following macro names are predefined in any translation unit.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
__cplusplus
baut auf den Wert 199711L(bis C + +11) oder 201103L(seit C++11)
Original:
expands to value 199711L(bis C + +11) or 201103L(seit C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(Makro konstant)
__STDC_HOSTED__
(C++11)
erweitert, um die Integerkonstante 1 wenn die Umsetzung gehostet wird (läuft unter OS), 0 Bei freistehenden (läuft ohne OS)
Original:
expands to the integer constant 1 if the implementation is hosted (runs under an OS), 0 if freestanding (runs without an OS)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(Makro konstant)
__FILE__
erweitert, um den Namen der aktuellen Datei als Zeichenkette literal
Original:
expands to the name of the current file, as a character string literal
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(Makro konstant)
__LINE__
erweitert, um der Quelldatei Zeilennummer, eine Integer-Konstante
Original:
expands to the source file line number, an integer constant
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(Makro konstant)
__DATE__
erweitert, um zum Zeitpunkt der Übersetzung, ein Zeichenfolgenliteral der Form "Mmm dd yyyy". Der Name des Monats ist, als ob durch std::asctime() generiert
Original:
expands to the date of translation, a character string literal of the form "Mmm dd yyyy". The name of the month is as if generated by std::asctime()
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(Makro konstant)
__TIME__
erweitert, um zum Zeitpunkt der Übersetzung, ein Zeichenfolgenliteral der Form "hh: mm: ss"
Original:
expands to the time of translation, a character string literal of the form "hh:mm:ss"
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(Makro konstant)
Die folgenden zusätzlichen Makronamen vorgegeben werden durch die Implementierungen .
Original:
The following additional macro names may be predefined by the implementations.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
__STDC__
Implementierung definiert Wert, falls vorhanden
Original:
implementation-defined value, if present
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(Makro konstant)
__STDC_VERSION__
(C++11)
Implementierung definiert Wert, falls vorhanden
Original:
implementation-defined value, if present
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(Makro konstant)
__STDC_ISO_10646__
(C++11)
erweitert, um eine Integer-Konstante der Form yyyymmL, wenn wchar_t Unicode verwendet, das Datum der letzten Revision des Unicode unterstützt anzeigt
Original:
expands to an integer constant of the form yyyymmL, if wchar_t uses Unicode, the date indicates the latest revision of Unicode supported
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(Makro konstant)
__STDC_MB_MIGHT_NEQ_WC__
(C++11)
expandiert nach 1, wenn große Zeichenkodierung des grundlegenden Zeichensatzes nicht gleich können ihre schmalen Codierung
Original:
expands to 1 if wide character encoding of the basic character set may not equal their narrow encoding
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(Makro konstant)
__STDCPP_STRICT_POINTER_SAFETY__
(C++11)
expandiert nach 1 wenn die Umsetzung hat strenge std::pointer_safety
Original:
expands to 1 if the implementation has strict std::pointer_safety
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(Makro konstant)
__STDCPP_THREADS__
(C++11)
expandiert nach 1 wenn das Programm mehr als ein Thread der Ausführung haben kann
Original:
expands to 1 if the program can have more than one thread of execution
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(Makro konstant)
Die Werte dieser Makros (außer __FILE__ und __LINE__) bleibt konstant über die Übersetzungseinheit. Versuche neu zu definieren oder undefine diese Makros Ergebnis in undefinierten Verhalten .
Original:
The values of these macros (except for __FILE__ and __LINE__) remain constant throughout the translation unit. Attempts to redefine or undefine these macros result in undefined behavior.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Hinweis: Im Rahmen der jede Funktion Körper, gibt es eine spezielle Funktion-local vordefinierte Variable namens __func__(seit C++11) als statischen Charakter Array, das die Namen der Funktion in der Umsetzung definierten Format definiert. Es ist keine Präprozessormakro, aber es wird zusammen mit __FILE__ und __LINE__, zB verwendet von assert .
Original:
Note: in the scope of every function body, there is a special function-local predefined variable named __func__(seit C++11), defined as a static character array holding the name of the function in implementation-defined format. It is not a preprocessor macro, but it is used together with __FILE__ and __LINE__, e.g. by assert.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten]Beispiel

#include <iostream>   //make function factory and use it#define FUNCTION(name, a) int fun_##name() { return a;}   FUNCTION(abcd, 12); FUNCTION(fff, 2); FUNCTION(kkk, 23);   #undef FUNCTION#define FUNCTION 34#define OUTPUT(a) std::cout << #a << '\n'   int main(){std::cout<<"abcd: "<< fun_abcd()<<'\n';std::cout<<"fff: "<< fun_fff()<<'\n';std::cout<<"kkk: "<< fun_kkk()<<'\n';std::cout<< FUNCTION <<'\n'; OUTPUT(million);//note the lack of quotes}

Output:

abcd: 12 fff: 2 kkk: 23 34 million
close