I have a question for you, c++.

Asked 2 years ago, Updated 2 years ago, 29 views

Hello. I've been studying, and I've found something I don't know; I'm asking you again.

(If you have any additional questions when you ask, is it right to update the previous article? Or can I write a new one? I don't know which one is right because it's my first time using a forum bulletin board like this. I'd appreciate it if you could let me know.)

I'm looking at the ICU code for the question, but I don't understand it, so I'm asking with a code attached.

#define U_ICU_VERSION_SUFFIX _56

#define U_DEF_ICU_ENTRY_POINT_RENAME(x,y) x ## y
#define U_DEF2_ICU_ENTRY_POINT_RENAME(x,y) U_DEF_ICU_ENTRY_POINT_RENAME(x,y)
#define U_ICU_ENTRY_POINT_RENAME(x)    U_DEF2_ICU_ENTRY_POINT_RENAME(x,U_ICU_VERSION_SUFFIX)

UErrorCode err = U_ZERO_ERROR;
U_ICU_ENTRY_POINT_RENAME(reinterpret_cast<void*>(g_icu_data_ptr), &err);

The above error is the error code defined in the ICU for the error code unification of all c++ compilers. The definition is typeefenumUErrorCode{error codes...} It's The above U_ZERO_ERROR is zero, indicating that there is no error.

g_icu_data_ptr contains the file path (ex: d:\test\icu\icudtl.dat like this).

The result is (reinterpret_cast(g_icu_data_ptr), &err) ##_56, and ## is saying to add x and y, right? X has two parameters, but I don't know how to attach it to _56.

Or does the usage of ## have other functions besides attaching two parameters?

appreciate it if you would give us (__)

.

c++

2022-09-22 20:24

1 Answers

I don't know the ICU reference well, so it's hard to answer correctly,

First of all, I will answer after looking at only C++ grammar in the code you posted.

// If you put it this way, you don't know exactly what _56 is.
// You can see from the context that it means version information
// I don't know if it's just a blank define, or what kind of define it's referring to.
#define U_ICU_VERSION_SUFFIX _56

// The code below clearly means connecting x and y on the code.
#define U_DEF_ICU_ENTRY_POINT_RENAME(x,y) x ## y

// Although the code below is converted to the code above without any additional work,
// Having this code is likely to have #defines with different definitions of the same name through #ifdef, etc.
// It is often used to have a complex response to multiple environments (Windows/Mac, or Unicode/ANSI).
#define U_DEF2_ICU_ENTRY_POINT_RENAME(x,y) U_DEF_ICU_ENTRY_POINT_RENAME(x,y)

// The code below seems to be intended to take a factor and call another macro function, including a specific constant value.
#define U_ICU_ENTRY_POINT_RENAME(x)    U_DEF2_ICU_ENTRY_POINT_RENAME(x,U_ICU_VERSION_SUFFIX)

// I'll leave this code out of the question.
UErrorCode err = U_ZERO_ERROR;

// In fact, if only the above codes exist, the code below is wrong.
// If the macro function via #define specifies the parameter as one in the declaration,
// Of course, it is right to hand over only one factor in the call book.
// I think there's an additional macro function declaration with the same name.
// I think you should look for the appropriate declaration.
U_ICU_ENTRY_POINT_RENAME(reinterpret_cast<void*>(g_icu_data_ptr), &err);


2022-09-22 20:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.