如何写 可移植C++代码(C++ Portability Guide--From Mozilla Develop Site)

C++ 入门(五)— 头文件(Header files) 这样做通常会导致违反单一定义规则 (ODR) 的情况,即头文件包含在多个源文件中。标头防护旨在确保给定头文件的内容不会多次复制到任何单个文件中,以防止重复定义。重复声明是可以的,但即使头文件由所有声明(无定义)组成,最好还是包含标头保护。请注意,标头防护不会阻止将头文件的内容(一次)复制到单独的项目文件中。这是一件好事,因为我们经常需要从不同的项目文件中引用给定标头的内容。 阅读详情

注:这个仅是我的学习笔记,完整的英文文章在这个(http://www.mozilla.org/hacking/portable-cpp.html)。


致谢:感谢这个文档的作者,为我学习提供了很好的资料^_^。

正文

/* Work In Progress  */

What follows is a set of rules, guidelines, and tips that we have found to be useful in making C++ code portable across many machines and compilers.

This information is the result of porting large amounts of code across about 25 different machines, and at least a dozen different C++ compilers. Some of these things will frustrate you and make you want to throw your hands up and say, ``well, that's just a stupid compiler if it doesn't do <insert favorite C++ feature>.'' But this is the reality of portable code. If you play by the rules, your code will seamlessly work on all of the Mozilla platforms and will be easy to port to newer machines.

We will endeavor to keep the information up to date (for example, sometimes a new compiler revision will lift a restriction). If you have updates on any of these tips, more information, more ideas, please forward them to Christopher Blizzard, Scott Collins, or David Baron.

If you find code in Mozilla that violates any of these rules, please report it as a bug. You can use bonsai to find the author.

None of these rules is absolute. If patch authors can demonstrate that what they want to do works on all the compilers we support, they're welcome to break, and revise, these rules. However, this is a lot of work, and is not recommended unless you have a very good reason for wanting to do it.


C++ portability rules.

  1. Be very careful when writing C++ templates.
  2. Don't use static constructors.
  3. Don't use exceptions.
  4. Don't use Run-time Type Information.
  5. Don't use C++ standard library features, including iostream
  6. Don't use namespace facility.
  7. main() must be in a C++ file.
  8. Use the common denominator between members of a C/C++ compiler family.
  9. Don't put C++ comments in C code.
  10. Don't put carriage returns in XP code.
  11. Put a new line at end-of-file.
  12. Don't put extra top-level semi-colons in code.
  13. C++ filename extension is .cpp.
  14. Don't mix varargs and inlines.
  15. Don't use initializer lists with objects.
  16. Always have a default constructor.
  17. Be careful with inner (nested) classes.
  18. Be careful of variable declarations that require construction or initialization.
  19. Make header files compatible with C and C++.
  20. Be careful of the scoping of variables declared inside for() statements.
  21. Declare local initialized aggregates as static.
  22. Expect complex inlines to be non-portable.
  23. Don't use return statements that have an inline function in the return expression.
  24. Be careful with the include depth of files and file size.
  25. Use virtual declaration on all subclass virtual member functions.
  26. Always declare a copy constructor and assignment operator.
  27. Be careful of overloaded methods with like signatures.
  28. Type scalar constants to avoid unexpected ambiguities.
  29. Always use PRBool for boolean variables in XP code.
  30. Use macros for C++ style casts.
  31. Don't use mutable.
  32. Use nsCOMPtr in XPCOM code.
  33. Don't use reserved words as identifiers.

Stuff that is good to do for C or C++.

  1. Always use the nspr types for intrinsic types.
  2. Do not wrap include statements with an #ifdef.
  3. #include statements should include only simple filenames.
  4. Macs complain about assignments in boolean expressions.
  5. Every source file must have a unique name.
  6. Use #if 0 rather than comments to temporarily kill blocks of code.
  7. Turn on warnings for your compiler, and then write warning free code.

Revision History.

Further Reading.


C++ portability rules.

  1. Be very careful when writing C++ templates.

    Don't use C++ templates unless you do only things already known to be portable because they are already used in Mozilla (such as patterns used by nsCOMPtr or CallQueryInterface) or are willing to test your code carefully on all of the compilers we support and be willing to back it out if it breaks.

  2. Don't use static constructors.

    Non-portable example:

      FooBarClass static_object(87, 92);

    void
    bar()
    {
    if (static_object.count > 15) {
    ...
    }
    }
    Static constructors don't work reliably either. A static initialized object is an object which is instanciated at startup time (just before main() is called). Usually there are two components to these objects. First there is the data segment which is static data loaded into the global data segment of the program. The second part is a initializer function that is called by the loader before main() is called. We've found that many compilers do not reliably implement the initializer function. So you get the object data, but it is never initialized. One workaround for this limitation is to write a wrapper function that creates a single instance of an object, and replace all references to the static initialized object with a call to the wrapper function:

    Portable example:

      static FooBarClass* static_object;

    FooBarClass*
    getStaticObject()
    {
    if (!static_object)
    static_object =
    new FooBarClass(87, 92);
    return static_object;
    }

    void
    bar()
    {
    if (getStaticObject()->count > 15) {
    ...
    }
    }
  3. Don't use exceptions.

    Exceptions are another C++ feature which is not very widely implemented, and as such, their use is not portable C++ code. Don't use them. Unfortunately, there is no good workaround that produces similar functionality.

    One exception to this rule (don't say it) is that it's probably ok, and may be necessary to use exceptions in some machine specific code. If you do use exceptions in machine specific code you must catch all exceptions there because you can't throw the exception across XP (cross platform) code.

  4. Don't use Run-time Type Information.

    Run-time type information (RTTI) is a relatively new C++ feature, and not supported in many compilers. Don't use it.

    If you need runtime typing, you can achieve a similar result by adding a classOf() virtual member function to the base class of your hierarchy and overriding that member function in each subclass. If classOf() returns a unique value for each class in the hierarchy, you'll be able to do type comparisons at runtime.

  5. Don't use C++ standard library features, including iostream

    Using C++ standard library features involves significant portability problems because newer compilers require the use of namespaces and of headers without .h, whereas older compilers require the opposite. This includes iostream features, such as cin and cout.

    Furthermore, using the C++ standard library imposes difficulties on those attempting to use Mozilla on small devices.

    There is one exception to this rule: it is acceptable to use placement new. To use it, include the standard header <new> by writing #include NEW_H.

  6. Don't use namespace facility.

    Support of namespaces (through the namespace and using keywords) is a relatively new C++ feature, and not supported in many compilers. Don't use it.

  7. main() must be in a C++ file.

    The first C++ compiler, Cfront, was in fact a very fancy preprocessor for a C compiler. Cfront reads the C++ code, and generates C code that would do the same thing. C++ and C startup sequences are different (for example static constructor functions must be called for C++), and Cfront implements this special startup by noticing the function called "main()", converting it to something else (like "__cpp__main()"), adding another main() that does the special C++ startup things and then calls the original function. Of course for all this to work, Cfront needs to see the main() function, hence main() must be in a C++ file. Most compilers lifted this restriction years ago, and deal with the C++ special initialization duties as a linker issue. But there are a few commercial compilers shipping that are still based on Cfront: HP, and SCO, are examples.

    So the workaround is quite simple. Make sure that main() is in a C++ file. On the Unix version of Mozilla, we did this by adding a new C++ file which has only a few lines of code, and calls the main main() which is actually in a C file.

  8. Use the common denominator between members of a C/C++ compiler family.

    For many of the compiler families we use, the implementation of the C and C++ compilers are completely different, sometimes this means that there are things you can do in the C language, that you cannot do in the C++ language on the same machine. One example is the 'long long' type. On some systems (IBM's compiler used to be one, but I think it's better now), the C compiler supports long long, while the C++ compiler does not. This can make porting a pain, as often times these types are in header files shared between C and C++ files. The only thing you can do is to go with the common denominator that both compilers support. In the special case of long long, we developed a set of macros for supporting 64 bit integers when the long long type is not available. We have to use these macros if either the C or the C++ compiler does not support the special 64 bit type.

  9. Don't put C++ comments in C code.

    The quickest way to raise the blood pressure of a Netscape Unix engineer is to put C++ comments (// comments) into C files. Yes, this might work on your Microsoft Visual C compiler, but it's wrong, and is not supported by the vast majority of C compilers in the world. Just do not go there.

    Many header files will be included by C files and included by C++ files. We think it's a good idea to apply this same rule to those headers. Don't put C++ comments in header files included in C files. You might argue that you could use C++ style comments inside #ifdef __cplusplus blocks, but we are not convinced that is always going to work (some compilers have weird interactions between comment stripping and pre-processing), and it hardly seems worth the effort. Just stick to C style /**/ comments for any header file that is ever likely to be included by a C file.

  10. Don't put carriage returns in XP code.

    While this is not specific to C++, we have seen this as more of an issue with C++ compilers, see Use the common denominator between members of a C/C++ compiler family. In particular, it causes bustage on at least the IRIX native compiler.

    On unix systems, the standard end of line character is line feed ('/n'). The standard on many PC editors is carriage return and line feed ("/r/n"), while the standard on Mac is carriage return ("/r"). The PC compilers seem to be happy either way, but some Unix compilers just choke when they see a carriage return (they do not recognize the character as white space). So, we have a rule that you cannot check in carriage returns into any cross platform code. This rule is not enforced on the Windows front end code, as that code is only ever compiled on a PC. The Mac compilers seem to be happy either way, but the same rule applies as for the PC - no carriage returns in cross platform code.

    MacCVS, WinCVS, and cygwin CVS when configured to use DOS line endings automatically convert to and from platform line endings, so you don't need to worry. However, if you use cygwin CVS configured for Unix line endings, or command line cvs on Mac OS X, you need to be somewhat careful.

  11. Put a new line at end-of-file.

    Not having a new-line char at the end of file breaks .h files with the Sun WorkShop compiler and it breaks .cpp files on HP.

  12. Don't put extra top-level semi-colons in code.

    Non-portable example:

      int
    A::foo()
    {
    };
    This is another problem that seems to show up more on C++ than C code. This problem is really a bit of a drag. That extra little semi-colon at the end of the function is ignored by most compilers, but it is not permitted by the standard and it makes some compilers report errors (in particular, gcc 3.4, and also perhaps old versions of the AIX native compiler). Don't do it.

    Portable example:

      int
    A::foo()
    {
    }
  13. C++ filename extension is .cpp.

    This one is another plain annoying problem. What's the name of a C++ file? file.cpp, file.cc, file.C, file.cxx, file.c++, file.C++? Most compilers could care less, but some are very particular. We have not been able to find one file extension which we can use on all the platforms we have ported Mozilla code to. For no great reason, we've settled on file.cpp, probably because the first C++ code in Mozilla code was checked in with that extension. Well, it's done. The extension we use is .cpp. This extension seems to make most compilers happy, but there are some which do not like it. On those systems we have to create a wrapper for the compiler (see STRICT_CPLUSPLUS_SUFFIX in ns/config/rules.mk and ns/build/*), which actually copies the file.cpp file to another file with the correct extension, compiles the new file, then deletes it. If in porting to a new system, you have to do something like this, make sure you use the #line directive so that the compiler generates debug information relative to the original .cpp file.

  14. Don't mix varargs and inlines.

    Non-portable example:

      class FooBar {
    void va_inline(char* p, ...) {
    // something
    }
    };
    The subject says it all, varargs and inline functions do not seem to mix very well. If you must use varargs (which can cause portability problems on their own), then ensure that the vararg member function is a non-inline function.

    Portable example:

      // foobar.h
    class FooBar {
    void
    va_non_inline(char* p, ...);
    };

    // foobar.cpp
    void
    FooBar::va_non_inline(char* p, ...)
    {
    // something
    }
  15. Don't use initializer lists with objects.

    Non-portable example:

      FooClass myFoo = {10, 20};
    Some compilers won't allow this syntax for objects (HP-UX won't), actually only some will allow it. So don't do it. Again, use a wrapper function, see Don't use static constructors.
  16. Always have a default constructor.

    Always have a default constructor, even if it doesn't make sense in terms of the object structure/hierarchy. HP-UX will barf on statically initialized objects that don't have default constructors.

  17. Be careful with inner (nested) classes.

    When using nested classes, be careful with access control. While most compilers implement (whether intentionally or not) the rules in the 2003 version of the C++ standard that give nested classes special access to the members of their enclosing class, some compilers implement what is described in the 1998 version of the standard, which is that nested classes have no special access to members of their enclosing class.

    Non-portable example:

    class Enclosing {
    private:
    int x;
    public:
    struct Nested {
    void do_something(Enclosing *E) {
    ++E->x;
    }
    };
    };

    portable example:

    class Enclosing {
    private:
    int x;
    public:
    struct Nested; // forward declare |Nested| so the |friend|
    // declaration knows what scope it's in.
    friend struct Nested; // make |Nested| a friend of its enclosing
    // class
    struct Nested {
    void do_something(Enclosing *E) {
    ++E->x;
    }
    };
    };

    A second non-portable example:

    class Enclosing {
    private:
    struct B;
    struct A {
    B *mB;
    };
    struct B {
    A *mA;
    };
    };

    and the equivalent portable example:

    class Enclosing {
    private:
    struct A;
    friend struct A;
    struct B;
    friend struct B;
    struct A {
    B *mB;
    };
    struct B {
    A *mA;
    };
    };
  18. Be careful of variable declarations that require construction or initialization.

    Non-portable example:

      void
    A::foo(int c)
    {
    switch(c) {
    case FOOBAR_1:
    XyzClass buf(100);
    // stuff
    break;
    }
    }
    Be careful with variable placement around if blocks and switch statements. Some compilers (HP-UX) require that any variable requiring a constructor/initializer to be run, needs to be at the start of the method -- it won't compile code when a variable is declared inside a switch statement and needs a default constructor to run.

    Portable example:

      void
    A::foo(int c)
    {
    XyzClass buf(100);

    switch(c) {
    case FOOBAR_1:
    // stuff
    break;
    }
    }
  19. Make header files compatible with C and C++.

    Non-portable example:

      /*oldCheader.h*/
    int existingCfunction(char*);
    int anotherExistingCfunction(char*);

    /* oldCfile.c */
    #include "oldCheader.h"
    ...

    // new file.cpp
    extern "C" {
    #include "oldCheader.h"
    };
    ...
    If you make new header files with exposed C interfaces, make the header files work correctly when they are included by both C and C++ files. If you start including an existing C header in new C++ files, fix the C header file to support C++ (as well as C), don't just extern "C" {} the old header file. Do this:

    Portable example:

      /*oldCheader.h*/
    PR_BEGIN_EXTERN_C
    int existingCfunction(char*);
    int anotherExistingCfunction(char*);
    PR_END_EXTERN_C

    /* oldCfile.c */
    #include "oldCheader.h"
    ...

    // new file.cpp
    #include "oldCheader.h"
    ...
    There are number of reasons for doing this, other than just good style. For one thing, you are making life easier for everyone else, doing the work in one common place (the header file) instead of all the C++ files that include it. Also, by making the C header safe for C++, you document that "hey, this file is now being included in C++". That's a good thing. You also avoid a big portability nightmare that is nasty to fix...

    Some systems include C++ in system header files that are designed to be included by C or C++. Not just extern "C" {} guarding, but actual C++ code, usually in the form of inline functions that serve as "optimizations". While we question the wisdom of vendors doing this, there is nothing we can do about it. Changing system header files, is not a path we wish to take. Anyway, so why is this a problem? Take for example the following code fragment:

    Non-portable example:

      /*system.h*/
    #ifdef __cplusplus
    /* optimization */
    inline int sqr(int x) {return(x*x);}
    #endif

    /*header.h*/
    #include <system.h>
    int existingCfunction(char*);

    // file.cpp
    extern "C" {
    #include "header.h"
    }
    What's going to happen? When the C++ compiler finds the extern "C" declaration in file.cpp, it will switch dialects to C, because it's assumed all the code inside is C code, and C's type free name rules need to be applied. But the __cplusplus pre-processor macro is still defined (that's seen by the pre-processor, not the compiler). In the system header file the C++ code inside the #ifdef __cplusplus block will be seen by the compiler (now running in C mode). Syntax Errors galore! If instead the extern "C" was done in the header file, the C functions can be correctly guarded, leaving the systems header file out of the equation. This works:

    Portable example:

      /*system.h*/
    #ifdef __cplusplus
    /* optimization */
    inline int sqr(int x) {return(x*x);}
    #endif

    /*header.h*/
    #include <system.h>
    extern "C" {
    int existingCfunction(char*);
    }

    // file.cpp
    #include "header.h"
    One more thing before we leave the extern "C" segment of the program. Sometimes you're going to have to extern "C" system files. This is because you need to include C system header files that do not have extern "C" guarding themselves. Most vendors have updated all their headers to support C++, but there are still a few out there that won't grok C++. You might have to do this only for some platforms, not for others (using #ifdef SYSTEM_X). The safest place to do extern "C" a system header file (in fact the safest place to include a system header file) is at the lowest place possible in the header file inclusion hierarchy. That is, push all this stuff down to the header files closer to the system code, don't do this stuff in the mail header files. Ideally the best place to do this is in the NSPR or XP header files - which sit directly on the system code.
  20. Be careful of the scoping of variables declared inside for() statements.

    Non-portable example:

      void
    A::foo()
    {
    for (int i = 0; i < 10; i++) {
    // do something
    }
    // i might get referenced
    // after the loop.
    ...
    }
    This is actually an issue that comes about because the C++ standard has changed over time. The original C++ specification would scope the i as part of the outer block (in this case function A::foo()). The standard changed so that now the i in is scoped within the for() {} block. Most compilers use the new standard. Some compilers (for example, Microsoft Visual C++ when used without an option supported only in newer versions, or the HP-UX compiler when used without a compiler option that we use) still use the old standard. It's probably better to be on the safe side and declare the iterator variable outside of the for() loop in functions that are longer than a few lines. Then you'll know what you are getting on all platforms:

    Portable example:

      void
    A::foo()
    {
    int i;
    for (i = 0; i < 10; i++) {
    // do something
    }
    // i might get referenced
    // after the loop.
    ...
    }
    Also you should not reuse a for loop variable in subsequent for loops or otherwise redeclare the variable. This is permitted by the current standard, but many compilers will treat this as an error. See the example below:

    Non-portable example:

      void
    A::foo()
    {
    for (int i; 0;) {
    // do something
    }
    for (int i; 0;) {
    // do something else
    }
    }

    Portable example:

      void
    A::foo()
    {
    for (int i; 0;) {
    // do something
    }
    for (int j; 0;) {
    // do something else
    }
    }
  21. Declare local initialized aggregates as static.

    Non-portable example:

      void
    A:: func_foo()
    {
    char* foo_int[] = {"1", "2", "C"};
    ...
    }
    This seemingly innocent piece of code will generate a "loader error" using the HP-UX compiler/linker. If you really meant for the array to be static data, say so:

    Portable example:

      void
    A:: func_foo()
    {
    static char *foo_int[] = {"1", "2", "C"};
    ...
    }
    Otherwise you can keep the array as an automatic, and initialize by hand:

    Portable example:

      void
    A:: func_foo()
    {
    char *foo_int[3];

    foo_int[0] = XP_STRDUP("1");
    foo_int[1] = XP_STRDUP("2");
    foo_int[2] = XP_STRDUP("C");
    // or something equally Byzantine...
    ...
    }
  22. Expect complex inlines to be non-portable.

    Non-portable example:

      class FooClass {
    ...
    int fooMethod(char* p) {
    if (p[0] == '/0')
    return -1;

    doSomething();
    return 0;
    }
    ...
    };
    It's surprising, but many C++ compilers do a very bad job of handling inline member functions. Cfront based compilers (like those on SCO and HP-UX) are prone to give up on all but the most simple inline functions, with the error message "sorry, unimplemented". Often times the source of this problem is an inline with multiple return statements. The fix for this is to resolve the returns into a single point at the end of the function. But there are other constructs which will result in "not implemented". For this reason, you'll see that most of the C++ code in Mozilla does not use inline functions. We don't want to legislate inline functions away, but you should be aware that there is some danger in using them, so do so only when there is some measurable gain (not just a random hope of performance win). Maybe you should just not go there.

    Portable example:

      class FooClass {
    ...
    int fooMethod(char* p) {
    int return_value;

    if (p[0] == '/0') {
    return_value = -1;
    } else {
    doSomething();
    return_value = 0;
    }
    return return_value;
    }
    ...
    };
    Or

    Portable example:

      class FooClass {
    ...
    int fooMethod(char* p);
    ...
    };

    int FooClass::fooMethod(char* p)
    {
    if (p[0] == '/0')
    return -1;

    doSomething();
    return 0;
    }
  23. Don't use return statements that have an inline function in the return expression.

    For the same reason as the previous tip, don't use return statements that have an inline function in the return expression. You'll get that same "sorry, unimplemented" error. Store the return value in a temporary, then pass that back.

  24. Be careful with the include depth of files and file size.

    Be careful with the include depth of files and file size. The Microsoft Visual C++1.5 compiler will generate internal compiler errors if you have a large include depth or large file size. Be careful to limit the include depth of your header files as well as your file size.

  25. Use virtual declaration on all subclass virtual member functions.

    Non-portable example:

      class A {
    virtual void foobar(char*);
    };

    class B : public A {
    void foobar(char*);
    };
    Another drag. In the class declarations above, A::foobar() is declared as virtual. C++ says that all implementations of void foobar(char*) in subclasses will also be virtual (once virtual, always virtual). This code is really fine, but some compilers want the virtual declaration also used on overloaded functions of the virtual in subclasses. If you don't do it, you get warnings. While this is not a hard error, because this stuff tends to be in headers files, you'll get so many warnings that's you'll go nuts. Better to silence the compiler warnings, by including the virtual declaration in the subclasses. It's also better documentation:

    Portable example:

      class A {
    virtual void foobar(char*);
    };

    class B : public A {
    virtual void foobar(char*);
    };
  26. Always declare a copy constructor and assignment operator.

    One feature of C++ that can be problematic is the use of copy constructors. Because a class's copy constructor defines what it means to pass and return objects by value (or if you prefer, pass by value means call the copy constructor), it's important to get this right. There are times when the compiler will silently generate a call to a copy constructor, that maybe you do not want. For example, when you pass an object by value as a function parameter, a temporary copy is made, which gets passed, then destroyed on return from the function. Maybe you don't want this to happen, maybe you'd always like instances of your class to be passed by reference. If you do not define a copy constructor the C++ compiler will generate one for you (the default copy constructor), and this automatically generated copy constructor might, well, suck. So you have a situation where the compiler is going to silently generate calls to a piece of code that might not be the greatest code for the job (it may be wrong).

    Ok, you say, "no problem, I know when I'm calling the copy constructor, and I know I'm not doing it". But what about other people using your class? The safe bet is to do one of two things: if you want your class to support pass by value, then write a good copy constructor for your class. If you see no reason to support pass by value on your class, then you should explicitly prohibit this, don't let the compiler's default copy constructor do it for you. The way to enforce your policy is to declare the copy constructor as private, and not supply a definition. While you're at it, do the same for the assignment operator used for assignment of objects of the same class. Example:

      class foo {
    ...
    private:
    // These are not supported
    // and are not implemented!
    foo(const foo& x);
    foo& operator=(const foo& x);
    };
    When you do this, you ensure that code that implicitly calls the copy constructor will not compile and link. That way nothing happens in the dark. When a user's code won't compile, they'll see that they were passing by value, when they meant to pass by reference (oops).
  27. Be careful of overloaded methods with like signatures.

    It's best to avoid overloading methods when the type signature of the methods differs only by 1 "abstract" type (e.g. PR_Int32 or int32). What you will find as you move that code to different platforms, is suddenly on the Foo2000 compiler your overloaded methods will have the same type-signature.

  28. Type scalar constants to avoid unexpected ambiguities.

    Non-portable code:

      class FooClass {
    // having such similar signatures
    // is a bad idea in the first place.
    void doit(long);
    void doit(short);
    };

    void
    B::foo(FooClass* xyz)
    {
    xyz->doit(45);
    }
    Be sure to type your scalar constants, e.g., PR_INT32(10) or 10L. Otherwise, you can produce ambiguous function calls which potentially could resolve to multiple methods, particularly if you haven't followed (2) above. Not all of the compilers will flag ambiguous method calls.

    Portable code:

      class FooClass {
    // having such similar signatures
    // is a bad idea in the first place.
    void doit(long);
    void doit(short);
    };

    void
    B::foo(FooClass* xyz)
    {
    xyz->doit(45L);
    }
  29. Type scalar constants to avoid unexpected ambiguities.

    Some platforms (e.g. Linux) have native definitions of types like Bool which sometimes conflict with definitions in XP code. Always use PRBool (PR_TRUE, PR_FALSE).

  30. Use macros for C++ style casts.

    Not all C++ compilers support C++ style casts:

    static_cast<type>(expression) (C++ style)

    (type) expression (C style)

    The header nscore.h defines portable cast macros that use C++ style casts on compilers that support them, and regular casts otherwise.

    These macros are defined as follows:

    #define NS_STATIC_CAST(__type, __ptr)      static_cast<__type>(__ptr)
    #define NS_CONST_CAST(__type, __ptr) const_cast<__type>(__ptr)
    #define NS_REINTERPRET_CAST(__type, __ptr) reinterpret_cast<__type>(__ptr)
    Note that the semantics of dynamic_cast cannot be duplicated, so we don't use it. See Chris Waterson's detailed explanation on why this is so.

    Example:

    Instead of:

    foo_t * x = static_cast<foo_t *>(client_data);
    bar_t * nonConstX = const_cast<bar_t *>(this);
    You should use:

    foo_t * x = NS_STATIC_CAST(foo_t *,client_data);
    bar_t * nonConstX = NS_CONST_CAST(bar_t *,this);
  31. Don't use mutable.

    Not all C++ compilers support the mutable keyword:

    You'll have to use the "fake this" approach to cast away the constness of a data member:

    void MyClass::MyConstMethod() const
    {
    MyClass * mutable_this = NS_CONST_CAST(MyClass *,this);

    // Treat mFoo as mutable
    mutable_this->mFoo = 99;
    }
  32. Use nsCOMPtr in XPCOM code.

    Mozilla has recently adopted the use of nsCOMPtr in XPCOM code.

    See the nsCOMPtr User Manual for usage details.

  33. Don't use reserved words as identifiers.

    According to the C++ Standard, 17.4.3.1.2 Global Names [lib.global.names], paragraph 1:

    Certain sets of names and function signatures are always reserved to the implementation:
    • Each name that contains a double underscore (__) or begins with an underscore followed by an uppercase letter (2.11) is reserved to the implemenation for any use.
    • Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.

Stuff that is good to do for C or C++.

  1. Always use the nspr types for intrinsic types.

    Always use the nspr types for intrinsic integer types. The only exception to this rule is when writing machine dependent code that is called from xp code. In this case you will probably need to bridge the type systems and cast from an nspr type to a native type.

  2. Do not wrap include statements with an #ifdef.

    Do not wrap include statements with an #ifdef. The reason is that when the symbol is not defined, other compiler symbols will not be defined and it will be hard to test the code on all platforms. An example of what not to do:

    Bad code example:

      // don't do this
    #ifdef X
    #include "foo.h"
    #endif
    The exception to this rule is when you are including different system files for different machines. In that case, you may need to have a #ifdef SYSTEM_X include.
  3. #include statements should include only simple filenames.

    Non-portable example:

      #include "directory/filename.h"
    Mac compilers handle #include path names in a different manner to other systems. Consequently #include statements should contain just simple file names. Change the directories that the compiler searches to get the result you need, but if you follow the Mozilla module and directory scheme, this should not be required.

    Portable example:

      #include "filename.h"
  4. Macs complain about assignments in boolean expressions.

    Another example of code that will generate warnings on a Mac:

    Generates warnings code:

      if ((a = b) == c) ...
    Macs don't like assignments in if statements, even if you properly wrap them in parentheses.

    More portable example:

      a=b;
    if (a == c) ...
  5. Every source file must have a unique name.

    Non-portable file tree:

      feature_x
    private.h
    x.cpp
    feature_y
    private.h
    y.cpp
    For Mac compilers, every file has to have a unique name. Don't assume that just because your file is only used locally that it's OK to use the same name as a header file elsewhere. It's not ok. Every filename must be different.

    Portable file tree:

      feature_x
    xprivate.h
    x.cpp
    feature_y
    yprivate.h
    y.cpp
  6. Use #if 0 rather than comments to temporarily kill blocks of code.

    Non-portable example:

      int
    foo()
    {
    ...
    a = b + c;
    /*
    * Not doing this right now.
    a += 87;
    if (a > b) (* have to check for the
    candy factor *)
    c++;
    */
    ...
    }
    This is a bad idea, because you always end up wanting to kill code blocks that include comments already. No, you can't rely on comments nesting properly. That's far from portable. You have to do something crazy like changing /**/ pairs to (**) pairs. You'll forget. And don't try using #ifdef NOTUSED, the day you do that, the next day someone will quietly start defining NOTUSED somewhere. It's much better to block the code out with a #if 0 , #endif pair, and a good comment at the top. Of course, this kind of thing should always be a temporary thing, unless the blocked out code fulfills some amazing documentation purpose.

    Portable example:

      int
    foo()
    {
    ...
    a = b + c;
    #if 0
    /* Not doing this right now. */
    a += 87;
    if (a > b) /* have to check for the
    candy factor
    */
    c++;
    #endif
    ...
    }
  7. Turn on warnings for your compiler, and then write warning free code.

    This might be the most important tip. Beware lenient compilers! What generates a warning on one platform will generate errors on another. Turn warnings on. Write warning free code. It's good for you.

 
C++官方自带可持久化平衡树rope的3000行源码 C++官方rope3000行源码 // SGI's rope class -*- C++ -*- // Copyright (C) 2001-2015 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms o 阅读详情

相关推荐

【脑电分析系列】第7篇:频域分析基石 — 功率谱密度(PSD)的计算与常见方法对比

本文探讨了脑电图(EEG)频域分析的核心方法——功率谱密度(PSD)。通过对比基于快速傅里叶变换的周期图法和更稳健的Welch's方法,指出后者通过分段、加窗和平均处理,能有效降低估计方差,更适合分析非稳态的脑电信号。文章详细解析了关键参数设置对频率分辨率和统计稳定性的影响,并提供了Python计算实现。PSD分析将复杂的脑电信号转换为直观的频域特征,为研究认知功能和神经疾病提供重要依据。

qq_32516809的博客 1819

文本编码检测库`chardet` 和 `uchardet`对比使用示例及注意事项

摘要:chardet和uchardet是用于二进制数据字符编码检测的实用工具,适用于卫星通信等场景。chardet是Python库,易用但较慢;uchardet(通过cchardet调用)是C++实现,速度快5-10倍。两者都支持多种编码并返回置信度,但chardet更灵活,cchardet更高效。建议组合使用:用cchardet快速扫描,对可疑数据再用chardet验证。注意优先检查BOM标记,避免用于加密/压缩数据。其他相关工具包括Linux的file、enca等。

悟空看八戒烤熟了没的专栏c)4Upqt4SeVk 1498

在WebView中对第三方H5页面的文本密码框添加自定义随机键盘

前言: 首先介绍一下这个需求的背景,由于公司是涉及到金融行业的需要与银行对接资金存管。出于保密性这里不直接列出公司名字和银行名字。从2018年国家对金融行业大整改以来,为了能够顺利通过备案,我们也跟着政府的脚步一步一步走向合规。 好了,大致就是因为要通过备案,必须把这个需求实现,否则将不会通过。 需求内容就是,当客户端有关资金交易的时候,会通过加密数据以及秘钥的方式把第三方银行的页面(充值、...

比较喜欢、笑的博客专栏 1588

C++ Header Files

C++ 头文件

qq_35934742的博客 564

LCD、LED、OLED、Mini LED、Micro LED、全阵列LED、QLED、QD-OLED、QNED、AMOLED是什么意思?

LCD(液晶显示器,Liquid Crystal Display)定义:LCD 是一种利用液晶材料控制光线通过的显示技术,需依靠背光源(如冷阴极荧光灯 CCFL 或 LED)照亮液晶层以形成图像。技术原理:液晶分子在电场作用下改变排列,控制背光通过的强度和颜色。液晶本身不发光,需外部光源。特点:结构包括背光层、液晶层、彩色滤光片和偏光片。响应时间较慢,黑色表现因背光漏光而偏灰。LED(发光二极管显示,Light Emitting Diode)定义。

中国最威武的城市!武功军威-武威,铁骨铮铮! 3439

哨兵一号数据下载

哨兵1号数据的下载过程

weixin_59617499的博客 5144

// Types used in iterator implementation -*- C++ -*-

//**/*/#endif/***///@{/***///@{//@}/***//***/#else#endif。

HJR_hjr_1234567的博客 777

一步一步实现基于COMSOL的单模光纤波导仿真

一步一步实现基于COMSOL的单模光纤波导仿真,简单易懂,跟着博客就能实现

君莫笑lucky的博客 1万+

五、C++中的头文件 Header Files

头文件 Header Files传统上用于声明某些函数类型,以便可以用于整个程序中。 例如:在一个文件1中创建函数,然后想在另一个文件2中使用,尝试编译此文件2时,C++不会直到这个文件1的存在,所以需要一个共同的地方来存放声明(并不是定义,因为函数的定义只可以有一次),声明中没有实际的函数定义,没有函数主体, 假定有个函数Log,作用时打印输出,接收一个const char "message",然后cout该信息 //Math.cpp #include <iostream> void

m0_66179815的博客 2729

uniapp - 超详细 H5 网页利用 uni.downloadFile 下载 URL 文件流并调用浏览器下载功能效果,前台通过请求后端接口获取文件并下载保存到本地(支持电脑PC与手机移动端H5)

uniapph5网页下载文件,uniapp网站下载文件流,uniapp的移动端h5实现接口url文件下载,uniapph5页面在浏览器中如何下载指定url文件流文件并保存到本地,uniapp移动端h5调用后端接口保存文件到本地,uniapph5通过下载后获得临时路径怎么让浏览器弹出下载,uniapp怎么请求接口下载到文件,得到Blob临时路径对象后如何下载到本地,浏览器怎么下载blob对象,uniapp二进制文件流下载,uniapph5中的文件流下载和指定的url下载详细教程,uniappapp移

🏆 前端领域优质创作者 1万+

以宠辱之戒写 SAP Fiori Elements,把标准能力当成身体,把扩展冲动当成大患

SAP Fiori Elements开发中常面临业务方追求"独特页面"的压力,但过度自定义会破坏框架价值。老子"宠辱若惊"的智慧提醒开发者:不应因用户称赞或批评而动摇架构原则。标准模板的价值在于确保业务语义、交互规范和后端服务的一致性。扩展应遵循官方API,将业务逻辑放在ABAP/CDS层而非前端控制器。成熟项目会平衡标准与定制,使用annotation表达UI行为,仅在必要时通过受支持的extension points进行增强,保持系统的长期可维护性。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1008

重走Java路-数据结构与算法-数组-手写ArrayList

重走Java路-数据结构与算法-数组-手写简单的ArrayList 上一回分享回顾完了Java的数组,因为数据结构与算法的知识相对独立,所以我决定接着数组回顾一下Java的数据结构。而ArrayList作为Java中最简单又最常用的集合类,正好适合拿来第一个开刀,不知道大家有没有去读过ArrayList的的源码,或者去简单实现一个ArrayList呢?今天我们就一起看看ArrayList的源码,同时手写一个简单的ArrayList。 learn ArrayList ArrayList源码分析 打开Arra

CrazyJavaWu的博客 287

【教程】OpenClaw交互入口解析WebChat与message CLI

WebChat和message CLI作为OpenClaw的直接交互入口,大大丰富了系统的使用场景和灵活性。理解它们的工作原理、适用场景和设计哲学,对于充分利用OpenClaw的全部功能至关重要。WebChat作为Gateway WebSocket上的聊天UI,提供了直观的图形界面,适合人工调试和系统监控;作为命令行工具,通过HTTP协议与Gateway交互,适合自动化和脚本化场景。两者相辅相成,共同构成了OpenClaw的"控制平面"。掌握正确的使用顺序。

海兰 312

头文件中的#ifndef #define #endif 作用

头文件中的#ifndef #define #endif 作用,防止头文件被重复包含

和尚洗头用霸王的专栏 7085

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

软件开发(1)

头文件(Header File)是一种在C/C++编程中使用的文件,通常以“.h”(C语言)或“.hpp”(C++语言)为扩展名。它包含了程序中需要使用的各种声明,如函数声明、类声明、宏定义、变量声明等。 类声明(主要针对C++) 在面向对象编程中,类是核心概念。头文件可以用来声明类的结构。例如,有一个头文件: 宏定义 头文件可以包含宏定义。例如,常见的宏定义: 变量声明(外部变量) 有时候需要在多个源文件中访问同一个全局变量。头文件可以用来声明这个外部变量。例如:

weixin_45179371的博客 1079

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

【C++】Header Files

头文件保护符,确保只将这个文件“include”一次,防止我们把单个头文件多次include到一个单一翻译单元里#ifndef_LOG_H // 头文件名... // 头文件内容...#endif。

m0_72946765的博客 135

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

C++中的声明、定义、头文件与源文件详解

声明向编译器介绍一个标识符(变量、函数、类等)的名称和类型,但不分配存储空间或提供实现。// 变量声明// 声明一个整型变量// 声明一个浮点变量// 函数声明// 类声明(前向声明)声明的特点仅告诉编译器标识符的类型和名称不分配内存(对于变量)不提供实现(对于函数)可以在同一编译单元中重复多次通常使用extern关键字明确表示变量声明定义不仅告诉编译器标识符的存在,还会分配内存(对于变量)或提供实现(对于函数和类)。// 变量定义// 定义并初始化一个整型变量。

kanhao100的博客 1995

STL algorithm源代码:stl_algo.h

&lt;span style="font-size:18px;"&gt;// Algorithm implementation -*- C++ -*- // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, // 2010, 2011 // Free Software Foundation, Inc. ...

weixin_34014277的博客 401

6.C++ header file

Header file 1.why we need header file 当我们在一个cpp中定义了一个函数想在另一个文件中使用这个函数时, 编译该文件,c++编译器不会知道该函数的存在,我们需要一个公用的地方来存放声明,注意是声明而非定义,我们只能定义函数1次,声明就是告诉编译器该函数的存在。当我们需要声明多个函数时,将声明挨个复制粘贴显然不是一个好方法。 通过#include 预处理语句来实...

qq_40427276的博客 1981

标准C /C++所有头文件

#include //定义各种数据类型最值常量 #include //定义本地化函数 #include //定义数学函数 #include //定义输入/输出函数 #include //定义杂项函数及内存分配函数 #include //字符串处理 #include //基于数组的输入/输出 #include //定义关于时间的函数 #include //宽字符处理及输入/输出 #

华 英雄 833

头文件(Header Files)和命名空间(Namespace)

c++中的“前两行”:命名空间和头文件

Gift-Isla 3330

C++ header file And Source file

C++ 的项目一旦过大,对文件的复用,整理等操作有了严格的要求.前一段时间就为自定义头文件的引入头疼了好久,现在说说我填过的坑.一.头文件,源文件的概念,关系这里不赘述了,网上的博客太多了,并且都比较详细.这里给个文章地址:http://www.cplusplus.com/forum/articles/10627/二.遇到的问题1.文件引用无误但....        yuan@localhost...

欢迎订阅 -- 小源笔迹 9703

文章标题

仅用于个人备查!config.h#pragma once #include <string> #include <map> #include <iostream> #include <fstream> #include <sstream> /* * \brief Generic configuration Class * */ class Config { // Dat

luoye_666qiji的博客 292

使用map遇到的两个问题及解决办法

  现定义一个map数据结构如下:map<tuple4, CTcpManage> m_mapTcp;   键值类型为结构体tuple4,存放TCP四元组,定义如下:      struct tuple4   {     u_int32_t sourceIP;     u_int32_t destIP;     unsigned short sport;     ...

weixin_30817749的博客 1234

C/C++头文件

C/C++头文件:C/C+程序通常由头文件(header files)和定义文件(definition files)组成。头文件作为一种包含功能函数、数据接口声明的载体文件,主要用于保证程序的声明(declaration);而定义文件用于保存程序的实现(implementation)。头文件一般由四部分内容组成:(1)头文件开头处的版权和版本声明;(2)预处理块;(3)inline函数的定义;(4)

Coding_Peasant的专栏 639
上一篇: 关于CE的系统调用
grrhard
博客等级 码龄21年 0粉丝 3原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值