C ++ #define my me ->

I am browsing the source of an older application. In this code, I see a lot of use of "mine."

He was identified as

#define my  me ->

But I'm not sure what exactly this means. Does this mean that if I use "mine", it will use "this →"?

I know this is not a good practice, but I need to understand what it is doing.

Thanks!

Edit:

More about the author:

/*
    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 ->

But I still do not see the definition of "I".

+4
source share
4 answers

#definevery simple in this question: when you use myin your code, it will be replaced by me ->, so code like this

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;

will actually mean

strcpy(me->first_name, "John");
strcpy(me->last_name, "John");
me->age = 23;

, , C. .

+7

my, me ->.

, me - , my.

class B {
public:
    void f() {}
};


#define my me ->
int main(int argc, char** argv) {

    B* b = new B();
    b my f(); // error, expanded to: b me -> f()
    B* me = new B();
    my f(); // OK, expanded to: me -> f()
    delete b;
    delete me;
    return 0;
}

#define me
#define my me ->
int main(int argc, char** argv) {
    B* b = new B();
    b my f(); //  OK, expanded to: b -> f();
    delete b;
    return 0;
}
0

, my me ->.

, -, my x x, , me . , , :

me->x
my x

, , - :

#define me this

me this -. , x :

my x
this->x

x , - , this->x.

, . , - -, .

, , , . , - int, my, , :

// This is what is written:
int my;
// This is what it becomes:
int me ->;
// Unless the #define for me is available, in which case you get:
int this ->

, , , , : , , .

, , , me , this ++, my this ->. , , ++, .

0

"my" "me → " .

, , "". .. , , Dog()

me->Dog()

my Dog()
0

All Articles