小编ant*_*ity的帖子

如何实现这样的 c++ 宏

#define idebug(...) \
  \#ifdef _DEBUG\
    printf(__VA_ARGS__);\
  \#endif\
#endif
Run Code Online (Sandbox Code Playgroud)

很难描述意图,这通常意味着我预先定义了一个宏 idebug 来保存一些代码。如果预定义了 _ DEBUG 标志,则打印输出。或者假装什么都没发生。

如果我们使用函数实现它,它将如下所示:

void idebug(...)
{
  #ifdef _DEBUG
    printf(...);
  #endif
}
Run Code Online (Sandbox Code Playgroud)

假设有一个程序

int main()                    
{                            
  int a = 10;         
  idebug("a:%d\n",a);      
}                           
Run Code Online (Sandbox Code Playgroud)

当我们处于调试阶段时,我们需要编译器的输出:

int main()                    
{                            
  int a = 10;         
  printf("a:%d\n",a);      
} 
Run Code Online (Sandbox Code Playgroud)

如果我们处于发布阶段,我们需要编译器的输出:

int main()                    
{                            
  int a = 10;         
} 
Run Code Online (Sandbox Code Playgroud)

c++ macros predefined-macro

3
推荐指数
1
解决办法
80
查看次数

关于rgb数值比较的困惑

我编写了一个程序,可以给出任何 RGB 值,并且可以从程序中找到相似的颜色。但结果有点令人困惑。程序有点长,主要是填充一些RGB数据。主要要点如下

//MyColor.h
#pragma once

#ifndef __MYCOLOR_H__
#define __MYCOLOR_H__

#include <windef.h>
#include <wingdi.h>

#include <vector>


namespace my
{

struct ColorData
{
    UINT8 family;
    UINT16 id;
    const char * name;
    const char * hex;
    UINT8   rgb[3];

    ColorData(UINT8 _family, UINT16 _id, const char *_name, UINT8 _r, UINT8 _g, UINT8 _b, const char * _hex)
    {
        family  = _family;
        id      = _id;
        name    = _name;
        hex     = _hex;
        rgb[0]  = _r;
        rgb[1]  = _g;
        rgb[2]  = _b;
    }
    ColorData(){};
};

/*

    MyColorSpace::myColorFamily …
Run Code Online (Sandbox Code Playgroud)

c++ rgb predefined-macro

0
推荐指数
1
解决办法
49
查看次数

标签 统计

c++ ×2

predefined-macro ×2

macros ×1

rgb ×1