c ++代码缺点/专业

Vir*_*cks 0 c++

下面我有一个在我的大多数简单程序中运行的代码.
我想知道它是好还是坏......以及缺点/专业人士.

.
win32头文件: win32.h

// example of a not realated code to exaplin the question
// this header have all win32 includes like win/proces/stdarg/string ... etc
#include <windows.h>
#include <process.h>
#include <stdarg.h>
Run Code Online (Sandbox Code Playgroud)

主头文件: inc.h

//this file includes the following

//top : the windows header file
#include "win32.h" // include the win32.h header file 

//the extern define which is the question
//the first include cause the INCS to be defined 
//any include afterwards causes the DD to go from 'nothing' into 'extern'
#ifndef INCS
    #define INCS
    #define DD
#else
    #define DD extern
#endif

// unrealted code to be more informative
//middle area of the file have the variables /defines or w/e
#ifndef VARS
    #define titlen L"my program"
#endif

DD wchar_t gtitle[512];
DD wchar_t gclass[512];
DD wchar_t gdir[32767];

//last area of the file
// this bottom area have the project's files' all included all headers and code
#include "resources.h"
#include "commonfunctions.cpp"
Run Code Online (Sandbox Code Playgroud)

然后所有文件都有这样的 commonfunctions.cpp

//a code just to be more informative and it's not realted to the question
#include "inc.h" // no need for includings ?

DD inline bool icmp( const char *String1, const char *String2 )
{
    if ( _stricmp( String1, String2 ) == 0 ) { return true; }
    return false;
}

DD inline bool scmp( const char *String1, const char *String2 )
{
    if ( strcmp( String1, String2 ) == 0 ) { return true; }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

DD指的是#define DD extern

所有全局变量都有DD面向它们,并且所有函数/ subs也都有DD,这将导致函数在第二次包含时被定义为所有文件中的extern

这有什么不好的一面吗?.我提出了这个想法,在小程序中根本没有问题.但在我将它应用于大型项目之前会有问题吗?.

.

现在回答问题

这里的DD意味着#define DD extern
DD将删除在代码之外或在头文件中执行psudo
的需要DD将删除在每个页面中定义外部变量的需要DD将不再需要在每个页面
中执行每个头文件的#includes文件

现在,在代码中演示的这个DD会在更大的代码中出现问题吗?

编辑:
我编辑的问题要更清楚了

提前致谢.

gru*_*czy 5

为什么使用char *而不是C++字符串?为什么要为标准函数编写自己的包装器?这些都不是一个好主意.

此外,如果你想返回某些条件的值,你应该这样做:

return _stricmp( String1, String2 ) == 0;
Run Code Online (Sandbox Code Playgroud)

而不是使用if.

在你的头文件里面总是放卫兵,像这样:

#ifndef HEADER_NAME_H
#define HEADER_NAME_H

/* code */

#endif // HEADER_NAME_H
Run Code Online (Sandbox Code Playgroud)

这样你就不会再包含两次了.

在C++中,没有理由使用#define像你一样定义consts:

#define titlen L"my program"
Run Code Online (Sandbox Code Playgroud)

而是简单地使用const关键字

const std::string titlen = "my program";
Run Code Online (Sandbox Code Playgroud)