我正在浏览旧应用程序的来源.在这段代码中,我看到很多用法"我的".
它被定义为
#define my me ->
但我不确定这意味着什么.这是否意味着如果我使用"我的",它将使用"this->"?
我知道这不是一个好习惯,但我需要了解它的作用.
谢谢!
编辑:
以下是作者的更多信息:
/* Use the macros 'I' and 'thou' for objects in the formal parameter lists (if the explicit type cannot be used). Use the macros 'iam' and 'thouart' as the first declaration in a function definition. After this, the object 'me' or 'thee' has the right class (for the compiler), so that you can use the macros 'my' and 'thy' to refer to members. Example: int Person_getAge (I) { iam (Person); return my age; } */ #define I Any void_me #define thou Any void_thee #define iam(klas) klas me = (klas) void_me #define thouart(klas) klas thee = (klas) void_thee #define my me -> #define thy thee -> #define his him ->
但我仍然看不到"我"的定义.
该#define
是在这件事情非常简单:当你使用my
你的代码,它会被取代me ->
,所以这样的代码
struct X { char first_name[100]; char last_name[100]; int age; } *me; me = malloc(sizeof(struct X)); strcpy(my first_name, "John"); strcpy(my last_name, "John"); my age = 23;
实际上意味着
strcpy(me->first_name, "John"); strcpy(me->last_name, "John"); me->age = 23;
虽然这个技巧可能看起来很可爱,但对于熟悉C语法的读者来说,这是非常误导的.我强烈建议不要在你的代码中使用它.