Using #define to a string in C++ Using #define to a string in C++ curl curl

Using #define to a string in C++


  1. The definition of the macro is preprocessor-style, it is just the sequence of characters, which happen to be within "". There is no type. The macro is expanded before the compiler (with its notion of types) starts the actual compilation.

  2. C++ will always concatenate all character-sequences-within-"". "A" "B" will always be handled as "AB" during building. There is not operator, no implicit operator either. This is often used to have very long string literals, spanning several line in code.


define's do not create a variable, so there is no concept of type. What happens is, before the source file is compiled, a preprocessor is run. It literally replaces all the instances of your macro, namely UPLOAD_FILE_AS with its value ("testImage.jpg").In other words, after the preprocessor stage, your code looks like this:

static const char buf_1 [] = "RNFR " "testImage.jpg";

And as C++ strings expand automatically, both of these strings become one: "RNFR testImage.jpg". You can find a better explanation here: link, mainly:

String literals placed side-by-side are concatenated at translation phase 6 (after the preprocessor). That is, "Hello," " world!" yields the (single) string "Hello, world!". If the two strings have the same encoding prefix (or neither has one), the resulting string will have the same encoding prefix (or no prefix).


exact type of defined UPLOAD_FILE_AS

There is no type. It is not a variable. It is a macro. Macros exist entirely outside of the type system.

The pre-processor replaces all instances of the macro with its definition. See the next paragraph for an example.

exact operation performed in second line

The operation is macro replacement. After the file is pre-processed, the second line becomes:

static const char buf_1 [] = "RNFR " "testImage.jpg";