Vous êtes sur la page 1sur 16

/

: : 13.05.2008

++

. , , / ++.

) .

, . ++.

++ 10 , , . , " comp.lang.c++.moderated , , . -

, " [1] "Why do you program in c++?" [2]. / ++ .

, , . , ,

++

. :

y y y y y y y y y

; Runtime( ; ) ; (Unit Testing); ; ; ; (Code Review); .

, " ( ) " [3]. .

1.
, ? , , , : 1. . . Debug, Release , Release . . 2. ( . 3. , .

?
. , .

(Release)

Release . ,

Hasp) ,

, ,

, . , .

4. . 5. . 6. . . 7. . , . , 8. . . , [ ]. 1 , . . , , , ( iff) d

, , . ,

2.
,
y

: , . , . -

, . ,
y

, Debug Release , .

.
y y

, . . , . ,

.
y

, . , ,

, .

[4]. , , . . : " [6]. , , . , printf,


int x = 5, y = 10; ... printf("Coordinate = (%d, %d) \n", x, y);

, . , , , "Logging In C++" [5] " , ,

, ,
#ifdef DEBUG_MODE #define WriteLog printf #else #define WriteLog(a) #endif WriteLog("Coordinate = (%d, %d) \n", x, y);

. WriteLog . ,

, _DEBUG, ReleaseDEBUG_MODE. ,

, , Visual C++ : "warning C4002: too many actual parameters for macro 'WriteLog'". , . :

#ifdef DEBUG_MODE #define WriteLog(a) printf a #else #define WriteLog( a) #endif WriteLog(("Coordinate = (%d, %d) \n", x, y));

, ,
#ifdef DEBUG_MODE #define WriteLog printf #else inline int StubElepsisFunctionForLog(...) { return 0; } static class StubClassForLog { public: inline void operator =(size_t) {} private: inline StubClassForLog &operator =(const StubClassForLog &)

{ return *this; } } StubForLogObject;

#define WriteLog \ StubForLogObject = sizeof StubElepsisFunctionForLog #endif WriteLog("Coordinate = (%d, %d) \n", x, y);

, DEBUG_MODE . ,

. ,
enum E_LogVerbose { Main, Full }; #ifdef DEBUG_MODE void WriteLog(E_LogVerbose, const char *strFormat, ...) { ... } #else ... #endif WriteLog (Full, "Coordinate = (%d, %d) \n", x, y);

, . ,

, , , , WriteLogMain, WriteLogFull . . , ,

, . , . ( N1. ) . ,

N1. , . . . 4000 20 . . , , , .

,5 000 .

WriteLog. , . , , . , ( (thread), N2).

N2. , , , , , N3. , .

N3. , , , , . :
class NewLevel { public: NewLevel() { WriteLog("__BEGIN_LEVEL__ \n"); } ~NewLevel() { WriteLog("__END_LEVEL__ \n"); } }; #define NEW_LEVEL NewLevel tempLevelObject; void MyFoo() { WriteLog("Begin MyFoo() \n");

. , . , , . .

NEW_LEVEL; int x = 5, y = 10; printf("Coordinate = (%d, %d) \n", x, y); WriteLog("Begin Loop: \n"); for (unsigned i = 0; i != 3; ++i) { NEW_LEVEL; WriteLog("i=%u\n", i); } }

:
Begin MyFoo() __BEGIN_LEVEL__ Coordinate = (5, 10) Begin Loop: __BEGIN_LEVEL__ i=0 __END_LEVEL__ __BEGIN_LEVEL__ i=1 __END_LEVEL__ __BEGIN_LEVEL__ i=2 __END_LEVEL__ Coordinate = (5, 10) __END_LEVEL__

:
Begin MyFoo() Coordinate = (5, 10) Begin Loop:

i=0 i=1 i=2 Coordinate = (5, 10)

3.
, , . 1. ++ 2. , 3. . 4. NEW_LEVEL. 5. 6. "#include" , . , / ++ . . , " Nemerle, Nemerle" [8]. / ++ : 1. . ++ . , , , . , , , : . , . . [7]. . , , . , , , , . . NEW_LEVEL . . , . : .

2.

. . . . / ++ ,

. . ,
EnableLogFunctionCallForFhisFile(true); ... ObjectsArray &objects = getObjects(); WriteLog("objects.size = %u", objects.size()); for (size_t i = 0; i != objects.size(); ++i) { WriteLog("object type = %i", int(objects [i] ->getType())); if (objects[i]->getType() != TYPE_1) ...

, .
ObjectsArray &objects = getObjects(); MyLog "objects.size = ", objects.size() for (size_t i = 0; i != objects.size(); ++i) { MyLog "object type = ", int(objects [i] ->getType()) if (objects[i]->getType() != TYPE_1) ...

,
thisfile.log.FunctionCall = ON ... ObjectsArray &objects = getObjects(); for (size_t i = 0;

i != <log>"objects.size = "objects.size()<log>; ++i) { LOG: "object type = " {as int} objects [i] ->getType();

if (objects[i]->getType() != TYPE_1) ...

. . , N4.

4. .

. N5.

5. . . . , . . , . . , : 1. . . 2. . 3. NEW_LEVEL. . . , , ++ , ++. , , , . . , ,

4. 5. . , 6. , .

. , . "#include"

. , . . , , . "#pragma".
ObjectsArray &objects = getObjects(); #pragma Log("objects.size = ", objects.size()) for (size_t i = 0; i != objects.size(); ++i) {

, ,

( . . , OpenMP, :

#pragma Log("object type = ", objects [i] ->getType()) if (objects[i]->getType() != TYPE_1) ...

. ,

"#pragma", . . .

4.
, , , , / ++. . , , . , ,

. , .

, . , , OpenC++ (OpenCxx) [9]. "source-to-source" . ++. OpenTS ) . VivaCore, OpenC++, . ++. Viva64 VivaMP. , , . . , The Wave C++ preprocessor library. , Microsoft Visual Studio 2005/2008 [10]. Synopsis T++ ( .

, !

, .

1. 2. 3. 4. 5. 6. 7. 8. 9. 10.

Casual Games Association. . http://www.viva64.com/go.php?url=34 Over at comp.lang.c++.moderated, there is a thread created by the c++ guru Scott Meyers on the subject: "Why do you program in c++?" http://www.viva64.com/go.php?url=35 . . http://www.viva64.com/go.php?url=36 , . Visual C++. http://www.viva64.com/art-1-1-640027853.html Petru Marginean. Logging In C++. http://www.viva64.com/go.php?url=37 . : . http://www.viva64.com/go.php?url=38 . , 1: . http://www.viva64.com/go.php?url=39 Kamil Skalski. Nemerle. http://www.viva64.com/go.php?url=40 Grzegorz Jakack. OpenC++ - A C++ Metacompiler and Introspection Library. http://www.viva64.com/go.php?url=41 , . VivaCore. http://www.viva64.com/art-2-1-696420215.html

, . .- . .,

" . .

",

VivaCore

Viva64, VivaMP.

: http://a-karpov.moikrug.ru E-Mail: karpov@viva64.com

Vous aimerez peut-être aussi