C And C++ Coding Standards

后端 未结 6 1989
不思量自难忘°
不思量自难忘° 2021-01-18 00:00

What are best practices with regards to C and C++ coding standards? Should developers be allowed to willy-nilly mix them together. Are there any complications when linking

6条回答
  •  梦毁少年i
    2021-01-18 00:48

    One should generally assume that c++ can throw exceptions, hence the c wrapper functions in your block, ought to catch them, and morph them into nice error codes that the c caller can digest.

    extern "c"
    {
        int nice_c_function_interface
        (
            void
        )
        {
            int returnStatus;
    
            try
            {
                 returnStatus = nice_cpp_function();
            }
            catch (NiceCppException& that)
            {
                 returnStatus = that.failure_code();  
            }
            catch (...)
            {
                cerr << "Oh Worse! an unexpected unknown exception" << endl;
    
                returnStatus = -1;  // Horrible unknown failure
            }
    
            return returnStatus;
        }
    }
    

提交回复
热议问题