首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

遇到编译有关问题,总是解决不了,向高手请问,写的是一个C语言抛出错误的代码

2012-03-07 
遇到编译问题,总是解决不了,向高手请教,写的是一个C语言抛出异常的代码码如下:接口(里面含有大量预处理内

遇到编译问题,总是解决不了,向高手请教,写的是一个C语言抛出异常的代码
码如下:
接口(里面含有大量预处理内容):
#ifndef   EXCEPT_INCLUDED
#define   EXCEPT_INCLUDED
#include   <setjmp.h>

                #define   T   Except_T
                typedef   struct   T
                {
                                char   *reason;
                }   T;

                typedef   struct   Except_Frame   Except_Frame;
                struct   Except_Frame
                {
                                Except_Frame   *prev;
                                jmp_buf   env;
                                const   char   *file;
                                int   line;
                                const   T   *exception;
                };


                enum
                {
                                Except_entered   =   0,  
Except_raised,  
Except_handled,
                                Except_finalized
                };

                #ifdef   WIN32
                                __declspec(thread)
                #endif


                extern   Except_Frame   *Except_stack;
                extern   const   Except_T   Assert_Failed;


                void   Except_raise(const   T   *e,   const   char   *file,   int   line);


                #define   RAISE(e)   Except_raise(   &(e),     __FILE__,     __LINE__   )
#define   RERAISE   Except_raise(   Except_frame.exception,\
Except_frame.file,   Except_frame.line   )


                #define   RETURN\
switch   (   Except_stack   =   Except_stack-> prev,   0   )\
default:\
return
#define   TRY\
do\  
{\
volatile   int   Except_flag;\
Except_Frame   Except_frame;\


Except_frame.prev   =   Except_stack;\
Except_stack   =   &Except_frame;\
Except_flag   =   setjmp(Except_frame.env);\
if   (Except_flag   ==   Except_entered)\
{
#defineEXCEPT(e)\
if   (Except_flag   ==   Except_entered)\  
Except_stack   =   Except_stack-> prev;\
}\
else   if   (Except_frame.exception   ==   &(e))\
{\
Except_flag   =   Except_handled;
#define   ELSE\
if   (Except_flag   ==   Except_entered)\
Except_stack   =   Except_stack-> prev;\
}\
else\
{\
Except_flag   =   Except_handled;
#define   FINALLY\
if   (Except_flag   ==   Except_entered)\
Except_stack   =   Except_stack-> prev;\
}\\
if   (Except_flag   ==   Except_entered)\
{\
Except_flag   =   Except_finalized;
#define   END_TRY\
if   (Except_flag   ==   Except_entered)\
Except_stack   =   Except_stack-> prev;\
}\
if   (Except_flag   ==   Except_raised)\
RERAISE;\
}while   (0)
                #undef   T  
#endif


实现代码:
#include   <stdlib.h>
#include   <stdio.h>
#include   "assert.h "
#include   "except.h "


#define   T   Except_T

#ifdef   WIN32
                __declspec(thread)
#endif

Except_Frame   *Except_stack   =   NULL;

void   Except_raise(const   T   *e,   const   char   *file,   int   line)
{
                Except_Frame   *p   =   Except_stack;
                assert(e);
                if   (p   ==   NULL)
                {
                                fprintf(stderr,   "Uncaught   exception ");
                                if   (e-> reason)
                                                fprintf(stderr,   "   %s ",   e-> reason);
                                else
                                                fprintf(stderr,   "   at   0x%p ",   e);
                                if   (file   &&   line   >   0)
                                                fprintf(stderr,   "   raised   at   %s:%d\n ",   file,   line);


                                fprintf(stderr,   "aborting...\n ");
                                fflush(stderr);
                                abort();
                }
                p-> exception   =   e;
                p-> file   =   file;
                p-> line   =   line;
                Except_stack   =   Except_stack-> prev;
                longjmp(p-> env,   Except_raised   );
}
这两段代码是基于接口与实现分离的形式,错误如下:
Compiling...
except.c
d:\程序\my   programmes\我的库函数接口与实现\except\my   except\except.h(53)   :   error   C2449:   found   '{ '   at   file   scope   (missing   function   header?)
d:\程序\my   programmes\我的库函数接口与实现\except\my   except\except.h(62)   :   error   C2017:   illegal   escape   sequence
D:\程序\my   programmes\我的库函数接口与实现\except\my   except\except.c(43)   :   fatal   error   C1004:   unexpected   end   of   file   found
Error   executing   cl.exe.

except.obj   -   3   error(s),   0   warning(s)

[解决办法]
d:\程序\my programmes\我的库函数接口与实现\except\my except\except.h(53) : error C2449: found '{ ' at file scope (missing function header?)
d:\程序\my programmes\我的库函数接口与实现\except\my except\except.h(62) : error C2017: illegal escape sequence
D:\程序\my programmes\我的库函数接口与实现\except\my except\except.c(43) : fatal error C1004: unexpected end of file found

按照这个错误改
错误说的也够明白了啊
[解决办法]
常量没付值吧
[解决办法]
Except_stack = Except_stack-> prev; \
} \ \ //---------
[解决办法]
楼主,你也在看这段呢
我也在看,晕的不行,呵呵
不过这书挺有意思的倒是
[解决办法]
程序应该没有问题,我用 VC6 试着编译,结果如下:
--------------------Configuration: except - Win32 Debug--------------------
Compiling...
except.c

except.obj - 0 error(s), 0 warning(s)

热点排行