Changeset 131 for cpp


Ignore:
Timestamp:
02/11/14 00:01:21 (11 years ago)
Author:
Maciej Komosinski
Message:

a better way to save/restore a preprocessor macro, unfortunately not a c++ standard (yet?)

Location:
cpp/frams/virtfile
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/virtfile/virtfile.cpp

    r123 r131  
    5959int fwrite(const void *ptr, size_t size, size_t nmemb, VirtFILE* f) {return f->Vwrite(ptr,size,nmemb);}
    6060
    61 //for some systems, we need to #undef feof which is unfortunately defined as a macro... we have to #undef just to be able to define our own function with this name. Same in virtfile.h
    62 #if defined __BORLANDC__ || defined _MSC_VER || defined __CYGWIN__ || defined SHP
     61
     62//since we want our own feof(VirtFILE*) function and some systems unfortunately define feof as a macro, we need to #undef it. Same as in virtfile.h
     63#if defined _MSC_VER || defined __CYGWIN__ || defined SHP
     64 #pragma push_macro("feof")
     65 #undef feof
     66#endif
     67#if defined __BORLANDC__ //does not support #pragma push_macro/pop_macro
    6368 #undef feof
    6469#endif
     
    6772
    6873//...and then restore the original macro:
     74#if defined _MSC_VER || defined __CYGWIN__ || defined SHP
     75 #pragma pop_macro("feof")
     76#endif
    6977#ifdef __BORLANDC__
    7078 #define feof(__f)     ((__f)->flags & _F_EOF)
    71 #endif
    72 #ifdef _MSC_VER
    73  #define feof(_stream)     ((_stream)->_flag & _IOEOF)
    74 #endif
    75 #ifdef __CYGWIN__
    76  #define feof(p)  __sfeof(p)
    77 #endif
    78 #ifdef SHP
    79  restore original macro... if you ever want to compile this code on bada
    8079#endif
    8180
  • cpp/frams/virtfile/virtfile.h

    r123 r131  
    7272
    7373
    74 //for some systems, we need to #undef feof which is unfortunately defined as a macro... we have to #undef just to be able to define our own function with this name. Same in virtfile.cpp
    75 #if defined __BORLANDC__ || defined _MSC_VER || defined __CYGWIN__ || defined SHP
     74//since we want our own feof(VirtFILE*) function and some systems unfortunately define feof as a macro, we need to #undef it. Same as in virtfile.cpp
     75#if defined _MSC_VER || defined __CYGWIN__ || defined SHP
     76 #pragma push_macro("feof")
     77 #undef feof
     78#endif
     79#if defined __BORLANDC__ //does not support #pragma push_macro/pop_macro
    7680 #undef feof
    7781#endif
     
    8084
    8185//...and then restore the original macro:
     86#if defined _MSC_VER || defined __CYGWIN__ || defined SHP
     87 #pragma pop_macro("feof")
     88#endif
    8289#ifdef __BORLANDC__
    8390 #define feof(__f)     ((__f)->flags & _F_EOF)
    84 #endif
    85 #ifdef _MSC_VER
    86  #define feof(_stream)     ((_stream)->_flag & _IOEOF)
    87 #endif
    88 #ifdef __CYGWIN__
    89  #define feof(p)  __sfeof(p)
    90 #endif
    91 #ifdef SHP
    92  restore original macro... if you ever want to compile this code on bada
    9391#endif
    9492
Note: See TracChangeset for help on using the changeset viewer.