C++ #define my me - >

 陈珍家615971 发布于 2023-02-13 17:48

我正在浏览旧应用程序的来源.在这段代码中,我看到很多用法"我的".

它被定义为

#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 ->

但我仍然看不到"我"的定义.

1 个回答
  • #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语法的读者来说,这是非常误导的.我强烈建议不要在你的代码中使用它.

    2023-02-13 17:51 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有